Interview Q&A / Object-Oriented Programming
Object-Oriented Programming interview questions
The four pillars, interfaces, abstract classes and design basics.
Prefer rapid revision? Practise Object-Oriented Programming short interview answers →
- What is encapsulation, and how do access modifiers help achieve it?
Encapsulation means keeping an object's data and the methods that change it together, and hiding the data so outside code can only change it through controlled methods. In Java, access modifiers (private, default, protected, public) decide who can see each member, and making fields private with validated methods is the usual way to encapsulate.
BeginnerIn-depth3 min read - What is the difference between protected and default (package-private) access in Java?
Default access lets only classes in the same package use the member. Protected allows the same package plus subclasses in any package, but through inheritance.
IntermediateQuick answer1 min read