Overloading vs Overriding and Their Rules
50 min · Beginner
Overloading gives one method name several parameter lists, chosen by the compiler. Overriding lets a subclass replace an inherited method, chosen by the JVM from the actual object. Interviewers test the rules for each and the puzzles where the two meet.
Topics in this lesson
- Comparison: signature, return type, access, exceptions, binding
- Can static, private or final methods be overridden?
- Covariant return types and @Override
- Predict the output: overload resolution
- Traps: return type only, reduced visibility, declared type
Interview questions this lesson answers
- What is method overloading?
- What is method overriding?
- What is the main difference between overloading and overriding?
- Which kind of polymorphism does each give?
- Can we overload by changing only the return type?
- Can we overload a method by changing only parameter names?
- What are the rules for overriding?
- Can an overriding method reduce visibility?
- Can an overriding method throw a broader checked exception?
- Can static methods be overridden?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.