Overloading vs Overriding Interview Questions
Explain polymorphism with a real example. What is the difference between overloading and 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.
Explain polymorphism with a real example. What is the difference between overloading and overriding?
Overloading is the same method name, different parameter list, picked at compile time. Overriding is a subclass replacing a parent method, picked at runtime from the actual object. Example I would draw: List of Payment, each has Pay(). CardPayment talks to a card gateway, WalletPayment talks to a wallet. The loop does not know the concrete type. In Java, changing only the return type is not overloading. Overriding has to stay substitutable — if Pay() cannot throw a new checked exception that callers do not expect, I have broken Liskov. Python is duck-typed but the same idea: same method name, different class, different behavior.
Can you override a static or private method?
No useful override for static — that is hiding. Private methods are not visible to children. Overriding needs an inherited instance method with the same signature. Overloading is same name, different parameters, compile time. I use @Override so the compiler catches mistakes.
Which is compile time and which is runtime?
Overloading is compile time. Overriding is runtime — the object's actual type. Printer.print(int) versus print(String) versus Animal a = new Dog(); a.speak(). That pair of examples is the whole answer.
Equals should be override or overload?
I override equals(Object) and hashCode together. If I write equals(MyClass) I overloaded and HashSet will not call it. That bug is famous. I mention identity versus value equality.
Overload with int and Integer in Java — what happens?
An int prefers the int overload. null prefers Integer. Overloading plus autoboxing is messy. I would rather name methods differently if the types are that close.
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