Java | final keyword | Question 4
class Base {
public final void show() {
System.out.println( "Base::show() called" );
}
}
class Derived extends Base {
public void show() {
System.out.println( "Derived::show() called" );
}
}
public class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}
|
(A) Derived::show() called
(B) Base::show() called
(C) Compiler Error
(D) Exception
Answer: (C)
Explanation: compiler error: show() in Derived cannot override show() in Base
Quiz of this Question
Last Updated :
28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...