У нас вы можете посмотреть бесплатно 9 What is Method Hiding in Java или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Great question—method hiding is a tricky and very popular Java interview topic, especially when talking about static methods 😄 Let’s make it clear, short, and example-driven. ________________________________________ 🔹 What is Method Hiding in Java? Method hiding happens when a child class defines a static method with the same signature as a static method in the parent class. • It is related to static methods • It is not overriding • Method call is resolved at compile time, based on reference type ________________________________________ 🔹 How Method Hiding is Done? (Example) class Parent { static void show() { System.out.println("Parent show()"); } } class Child extends Parent { static void show() { // This hides Parent's show() System.out.println("Child show()"); } } public class Test { public static void main(String[] args) { Parent p = new Child(); p.show(); // Which one will be called? Child c = new Child(); c.show(); } } 🔹 Output: Parent show() Child show() ________________________________________ 🔹 Why this is Method Hiding? • show() is static • Static methods belong to class, not object • Method call depends on reference type, not object type • So: • Parent p = new Child(); • p.show(); // Calls Parent.show() Even though object is Child 👉 This is called method hiding, not overriding. ________________________________________ 🔹 Key Interview Points • ✅ Only static methods can be hidden • ❌ Instance methods are overridden, not hidden • ✅ Resolved at compile time • ✅ Depends on reference type • ❌ No runtime polymorphism for static methods ________________________________________ 🔹 One-Line Interview Answer Method hiding occurs when a child class defines a static method with the same signature as a static method in the parent class, and the method call is resolved based on the reference type at compile time. ________________________________________ 🔹 Quick Comparison: Overriding vs Hiding Feature Method Overriding Method Hiding Applies to Instance methods Static methods Binding Runtime (dynamic) Compile time (static) Polymorphism ✅ Yes ❌ No Based on Object type Reference type ________________________________________ 🔹 Memory Trick 🧠 static methods don’t override, they hide ________________________________________ If you want, I can also give you tricky output-based questions on method hiding vs overriding (interviewers love those 😄).