Java | Inheritance | Question 3
class Base { public static void show() { System.out.println("Base::show() called"); } } class Derived extends Base { public static 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
Answer: (A)
Explanation: Like C++, when a function is static, runtime polymorphism doesn’t happen.
Quiz of this Question
Recommended Posts:
- Java | Inheritance | Question 4
- Java | Inheritance | Question 5
- Java | Inheritance | Question 9
- Java | Inheritance | Question 1
- Java | Inheritance | Question 8
- Java | Inheritance | Question 2
- Java | Inheritance | Question 7
- Java | Inheritance | Question 9
- Inheritance in Java
- Java and Multiple Inheritance
- Interfaces and Inheritance in Java
- Using final with Inheritance in Java
- Comparison of Inheritance in C++ and Java
- Inheritance and constructors in Java
- Delegation vs Inheritance in Java



