A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Inheritance pbs
prerna boja
Ranch Hand
Joined: Aug 19, 2004
Posts: 67
posted
Jan 25, 2005 15:11:00
0
Hi all,
package Food;
public class Zoo {
public void coolMethod()
{
System.out.println("hello");
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------
package Food;
import Food.Zoo;
public class Moo extends Zoo{
public static void main(
String
[] args) {
Zoo z= new Zoo();
System.out.println("A Zoo Says, " +z.coolMethod());---------- //1
}
}
I am getting an error saying "Void" type not allowed here on line 1.
can anybody tell what wrong I have done.
Steven Bell
Ranch Hand
Joined: Dec 29, 2004
Posts: 1071
posted
Jan 25, 2005 15:32:00
0
First, use code tags when you post code. (look below next to all the little faces as your posting)
In your code the method 'coolMethod()' has a return value of void, it doesn't return anything, so it can't be concatinated to the string on line 1.
I think what you want to do is return "Hello" rather than System.out.println("Hello")
I agree. Here's the link:
jrebel
subject: Inheritance pbs
Similar Threads
Simple Q, I'm newbie
why is this code not running ?
need help understanding access control
Parent child object problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter