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() { } }
--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---