• Post Reply Bookmark Topic Watch Topic
  • New Topic

TestAnimals program gives incompatibility error  RSS feed

 
Greenhorn
Posts: 3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I'm a Newbie here. Planning to to give my SCJP. So first step is practicing the study guide.
And here I'm stuck at the TestAnimals in Chapter 2.
____________________________________________________________
public class TestAnimals{
public static void main(String [] args){
Animal a = new Animal();
Animal b = new Horse();
a.eat();
b.eat(); }}
class Animal { public void eat() { System.out.println("Generic animal eating"); }}
class Horse { public void eat() { System.out.println("Horse eating"); }}
__________________________________________________________________________
java:4:error:incompatible types
Animal b = new Horse();
^
required : Animal
found : Horse
_____________________________________
Isnt this program supposed to run without errors? Please help. Thanks
 
Sreelu Yeddanapudi
Greenhorn
Posts: 3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry! I was supposed to be overriding. And I missed saying "Horse extends Animal"
It works now
 
Marshal
Posts: 57260
175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting it out, and welcome to the Ranch
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!