Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance pbs

 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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")
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic