What is method hiding vs method overriding?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex OOP Concepts topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Both define a method in a subclass with the same signature as a parent class method, but they behave very differently: Method overriding (instance methods): replaces the parent's method. The correct version is determined at RUNTIME based on the actual object type — true polymorphism: class Parent { public void display() { System.out.println("Parent display"); } } class Child extends Parent { @Override public void display() { System.out.println("Child display"); } } Parent obj = new Child(); obj.display(); // "Child display" -- RUNTIME decision. Method hiding (static methods): the child class defines a static method with the same signature. No overriding — the version called is determined at COMPILE TIME based on the reference type: class Parent { public static void staticMethod() { System.out.println("Parent static"); } } class Child extends Parent { public static void staticMethod() { System.out.println("Child static"); // HIDES, doesn't override } } Parent p = new Child(); p.staticMethod(); // "Parent static" -- compile-time based on reference type! Child c = new Child(); c.staticMethod(); // "Child static" -- based on reference type. Why this distinction matters: static methods are resolved at compile time; instance methods are resolved at runtime. "Overriding" static methods is a common misconception — you can hide them but not override. The @Override annotation would fail on a static method in Java. Field hiding: similar — subclass fields with same name HIDE parent fields, not override. Access: parent.field vs child.field — type of reference determines which field is accessed.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.