Interview Q&A / Java
Java interview questions
Collections, the JVM, strings, exceptions and threads, the backbone of most campus placement rounds.
Prefer rapid revision? Practise Java short interview answers →
- When should you use composition instead of inheritance in Java?
Use inheritance for a true is-a relationship and composition for has-a. Composition is usually safer because the classes stay loosely coupled and you can change the part at runtime, while inheritance ties the child tightly to the parent.
IntermediateQuick answer1 min read