BCA / B.Tech 9 min read

Method Hiding in Java

Quick Summary & Key Takeaways

  • • Subject Focus: Java Notes in English (BCA / B.Tech Syllabus)
  • • Core Topic: Method Hiding in Java - General Topics
  • • Overview: What is Method Hiding in Java? Method hiding is a concept that applies specifically to static methods in an inheritance hierarchy. If a subclass define...
  • • Key Concepts: Java method hiding, Static methods inheritance Hindi, Hiding vs overriding,

What is Method Hiding in Java?

Method hiding is a concept that applies specifically to static methods in an inheritance hierarchy. If a subclass defines a static method that has the same signature (name and parameter list) as a static method in its superclass, the subclass's method hides the superclass's method instead of overriding it.

The key difference is how the method call is resolved. Method hiding uses compile-time binding (static binding), meaning the method that gets called is determined by the reference type, not the object type at runtime.


Method Hiding vs. Method Overriding:
Feature Method Hiding Method Overriding
Applies to static methods Instance (non-static) methods
Binding Compile-time (Static) Run-time (Dynamic)
Resolution Based on the reference type Based on the object type

Example:

class Parent {
    static void display() {
        System.out.println("Static method from Parent");
    }
}

class Child extends Parent {
    // This static method HIDES the one in the Parent class
    static void display() {
        System.out.println("Static method from Child");
    }
}

public class Main {
    public static void main(String[] args) {
        Parent p = new Child();
        
        // The reference type is Parent, so the Parent's static method is called.
        // The fact that `p` points to a Child object is irrelevant for static methods.
        p.display(); 
    }
}
        
Output:
Static method from Parent

Frequently Asked Questions (FAQs)

What is Method Hiding in Java?.
Understanding Method Hiding in Java is fundamental to mastering Java Notes in English. It covers crucial concepts, solved problems, and revision points essential for academic and entrance exam success.
You can read free solved examples, detailed explanations, and key formulas for Method Hiding in Java directly on the NotesMedia website or by downloading the NotesMedia App.