+ 3
why System.out.println("Grr..."); //"Grr..." is not printed ? // but the class dog is extends animal can anyone explain m
class Animal { public void makeSound() { System.out.println("Grr..."); } } class Cat extends Animal { public void makeSound() { System.out.println("Meow"); } } class Dog extends Animal { public void makeSound() { System.out.println("Woof"); } } class Program { public static void main(String args[ ]) { Animal a = new Dog(); Animal b = new Cat(); a.makeSound(); b.makeSound(); } } why System.out.println("Grr..."); //"Grr..." is not printed ? // but the class dog is extends animal can anyone explain me and what if i want to print the line ?
3 Respuestas
+ 4
Because the Animal's makeSound is overridden by the Dog's makeSound
+ 4
thanks @~ swim ~ and @Baptiste E for guiding and helping me
+ 2
Is Polymorphism and Overriding are same or different ?