Interview Question

Can we override static methods?

Static methods use hiding and compile-time selection, not overriding.

💡 Concept ✅ Quick Revision ☕ Java

Answer

Static methods are hidden, not overridden. • Static invocation is selected using the compile-time type or class name. • A subclass may declare a compatible static method with the same signature. • Using an instance to call a static method is legal in some contexts but misleading.

Example

Code
class Parent { static String value() { return "parent"; } }
class Child extends Parent { static String value() { return "child"; } }
Parent item = new Child();
System.out.println(item.value());
Output
parent

Quick Revision

Static methods use hiding and compile-time selection, not overriding.