OOP

Hiding vs Overriding Interview Questions

What is method hiding vs method overriding? — spoken sample answer for Indian interviews.

  • 5Questions with answers
  • 3Difficulty levels

Questions (5)

Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.

Question 1
Interview Intermediate
Question

What is method hiding vs method overriding?

Answer:

Overriding is an instance method with the same signature. The runtime type wins: Super s = new Sub(); s.instance() runs Sub. Hiding is what static methods do, and what C# 'new' methods do. Binding follows the compile-time type: s.staticMethod() still runs Super if the variable is typed Super. I avoid hiding because it surprises readers. If they show me a snippet with static methods and a subclass, I walk through the reference type first, then the object type.

Question 2
Interview Advanced
Question

What is method hiding?

Answer:

A child declares a static method with the same signature, or C# new on an instance method. Calls follow the compile-time type. Overriding uses virtual dispatch. I would not hide by accident.

Question 3
Interview Intermediate
Question

Why virtual in C# but not always in Java?

Answer:

Java instance methods are virtual by default. C# needs virtual and override. That is why C# hiding with new is more visible. The dispatch idea is the same. Defaults differ.

Question 4
Interview Advanced
Question

Fields are not polymorphic. What does that mean?

Answer:

If parent and child both have field x, which field you see depends on the reference type. Methods override, fields hide. I would not put important state in hiding fields. I would use methods.

Question 5
Interview Intermediate
Question

How would you demo hiding versus overriding in two minutes?

Answer:

Parent p = new Child(); p.method() for an overridden method — Child runs. Same shape with a static or hidden field — Parent's version shows. Two snippets. If C# I add virtual. If Java I add static.

Practice with AI mock interviews

Run OOP mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.

Free to start · No credit card required