What will be the output of this code?

Last Updated :
Discuss
Comments

What will be the output of this code?

Java
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

Share your thoughts in the comments