• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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: 60795
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting it out, and welcome to the Ranch
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!