Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Java | Inheritance | Question 3

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Java




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();
    }
}



(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

My Personal Notes arrow_drop_up
Last Updated : 13 Oct, 2021
Like Article
Save Article
Similar Reads