no need to define ass method in both classes.  you should cast the ass
method . because reference type is anymal.

ie. ((Horse)b).ass();//careful on putting parenthesis

On Sun, Jul 26, 2009 at 7:13 PM, ali googerdi <googe...@gmail.com> wrote:

>
> It's because you didn't define the ass method in Animal class but you
> have define eat in both classes.
>
> On Jul 26, 4:29 pm, ANUJ KUMAR <kumar.anuj...@gmail.com> wrote:
> > class TestAnimals {
> > public static void main (String [] args) {
> > Animal a = new Animal();
> > Animal b = new Horse(); //Animal ref, but a Horse object
> > a.eat(); // Runs the Animal version of eat()
> > b.eat(); // Runs the Horse version of eat()
> > a.anuj();
> > b.anuj();
> > b.ass();//*WHY DOES IT GIVE A COMPILER ERROR WHEREAS THE EAT METHOD RUNS
> > FINE*}
> > }
> >
> > class Animal {
> > void anuj()
> > {
> > System.out.println("anuj");}
> >
> > public void eat() {
> > System.out.println("Generic Animal Eating Generically");}
> > }
> >
> > class Horse extends Animal {
> > void ass()
> > {
> > System.out.println("ass");}
> >
> > public void eat() {
> > System.out.println("Horse eating hay, oats, and horse treats");}
> >
> > public void buck() { }
> >
> > }
>
> >
>


-- 
෴ ~ කසුන්/Kasun ~෴

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to