Java | Inheritance | Question 2
class Base { final public void show() { System.out.println("Base::show() called"); } } class Derived extends Base { public void show() { System.out.println("Derived::show() called"); } } class Main { public static void main(String[] args) { Base b = new Derived();; b.show(); } } |
chevron_right
filter_none
(A) Base::show() called
(B) Derived::show() called
(C) Compiler Error
(D) Runtime Error
Answer: (C)
Explanation: Final methods cannot be overridden. See the compiler error here.
Quiz of this Question
Recommended Posts:
- Java | Inheritance | Question 8
- Java | Inheritance | Question 5
- Java | Inheritance | Question 3
- Java | Inheritance | Question 9
- Java | Inheritance | Question 4
- Java | Inheritance | Question 9
- Java | Inheritance | Question 1
- Java | Inheritance | Question 7
- Inheritance in Java
- Java and Multiple Inheritance
- Interfaces and Inheritance in Java
- Inheritance and constructors in Java
- Comparison of Inheritance in C++ and Java
- Using final with Inheritance in Java
- Delegation vs Inheritance in Java



