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 are the four pillars of object-oriented programming?
Encapsulation (keep data and the code that uses it together, and hide the inside), abstraction (show only what matters), inheritance (reuse and extend a parent class) and polymorphism (one interface, many behaviours).
BeginnerIn-depth2 min read - What is a constructor, and what is constructor chaining?
A constructor is a special method with the class's name and no return type that runs when an object is created, to set its starting state. Constructor chaining is one constructor calling another, either in the same class with this(...) or in the parent class with super(...), so setup code is written once.
BeginnerIn-depth3 min read - 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 method overloading and method overriding?
Overloading means several methods in the same class share a name but take different parameters, and the compiler picks one. Overriding means a subclass gives its own version of a method it inherited, with the same signature, and the JVM picks the version at runtime based on the actual object.
BeginnerIn-depth3 min read