What will be the output of this code?
class Animal { void makeSound() { System.out.println("Animal makes a sound"); } } class Dog extends Animal { void makeSound() { System.out.println("Dog barks"); } } public class Main { public static void main(String[] args) { Animal a = new Dog(); a.makeSound(); } }
Animal makes a sound
Dog barks
Compilation error
Runtime error
This question is part of this quiz :
Java Inheritance and Abstraction,50 Java Language MCQs with Answers