Explain Java polymorphism with a worked distinction between compile-time overload selection and runtime overriding. Cover inherited overloads, reference types, static methods, and the purpose of @Override.
Explain Java Polymorphism, Overloading, and Overriding
Company: Apple
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
Explain polymorphism in Java, then distinguish method overloading from method overriding. Use a small example to show how the declared reference type and the runtime object type affect a call.
### Clarifying Questions
Focus on ordinary instance methods and reference types. Discuss static methods separately rather than assuming all methods use runtime dispatch.
### Part 1 — Polymorphism
How can a parent or interface reference refer to a subtype object, and what determines the behavior of an overridden call?
#### What This Part Should Cover
Separate the operations available through the reference type from the implementation chosen at runtime.
### Part 2 — Overloading and Overriding
What makes two methods overloads, and what makes a subclass method an override? Can changing only a return type create an overload?
#### What This Part Should Cover
Explain compile-time overload selection, runtime instance-method dispatch, and inherited overloads.
### What a Strong Answer Covers
Accurate definitions with a worked example, including why overload resolution and overriding are different stages.
### Follow-up Questions
- What does @Override help detect?
- Do fields and static methods participate in the same runtime dispatch as overridden instance methods?
Overview: Explain Java polymorphism with a worked distinction between compile-time overload selection and runtime overriding. Cover inherited overloads, reference types, static methods, and the purpose of @Override.
Explain polymorphism in Java, then distinguish method overloading from method overriding. Use a small example to show how the declared reference type and the runtime object type affect a call.
Clarifying Questions Guidance
Focus on ordinary instance methods and reference types. Discuss static methods separately rather than assuming all methods use runtime dispatch.
Part 1 — Polymorphism
How can a parent or interface reference refer to a subtype object, and what determines the behavior of an overridden call?
What This Part Should Cover Guidance
Separate the operations available through the reference type from the implementation chosen at runtime.
Part 2 — Overloading and Overriding
What makes two methods overloads, and what makes a subclass method an override? Can changing only a return type create an overload?
What This Part Should Cover Guidance
Explain compile-time overload selection, runtime instance-method dispatch, and inherited overloads.
What a Strong Answer Covers Guidance
Accurate definitions with a worked example, including why overload resolution and overriding are different stages.
Follow-up Questions Guidance
What does @Override help detect?
Do fields and static methods participate in the same runtime dispatch as overridden instance methods?