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 →
- What is the difference between encapsulation and abstraction in Java?
Abstraction hides complexity by showing only what a user needs, usually through interfaces or abstract classes. Encapsulation hides data by keeping fields private and exposing controlled methods. One is about design, the other about protection.
BeginnerQuick answer1 min read - 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