What will be the output of the following code?

Last Updated :
Discuss
Comments

What will be the output of the following code?

Java
class A {
    void display() {
        System.out.println("Class A");
    }
}
class B extends A {
    void display() {
        System.out.println("Class B");
    }
}
public class Main {
    public static void main(String[] args) {
        A obj = new B();
        obj.display();
    }
}


Class A

Class B

Compilation error

Runtime error

Share your thoughts in the comments