The Wayback Machine - https://web.archive.org/web/20250730015110/https://www.geeksforgeeks.org/questions/c-final-class-complex-private-final-double-re/

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