• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Compile time erroe in the code.

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is compile output i get as below?





Output:
---------- Compile ----------
Sub_class.java:8: 'void' type not allowed here
System.out.println(Sub_class.return_Number());
^
Sub_class.java:9: 'void' type not allowed here
System.out.println(Super_class.return_Number());
^
2 errors
Normal Termination
Output completed (0 sec consumed).
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're calling PrintStream's println() method and passing in the return value of the return_Number() method. However, the return type of the return_Number() method is void, which is why it's not valid to pass the result of this method as an argument to the println() method - the return_Number() method doesn't yield a return value.
[ October 07, 2008: Message edited by: Jelle Klap ]
 
Ranch Hand
Posts: 179
Mac Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The return type of both the methods that are called in the println statement are void, So it doesnot return anything and thus the error.
 
It was the best of times. It was the worst of times. It was a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic