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 the Observer pattern? Explain with a cricket score example.
A subject keeps a list of observers and tells all of them when its state changes. Observers subscribe and unsubscribe at runtime, and the subject does not need to know what they do with the news.
BeginnerQuick answer1 min read - What is the Singleton pattern and how do you implement it?
Singleton ensures a class has exactly one instance and gives a global access point to it. Make the constructor private, keep the instance in a static field, and return it from a static method.
BeginnerQuick answer1 min read - Why use a factory instead of calling new directly?
A factory hides which concrete class is created and how. Callers ask for what they need, and creation rules can change in one place without touching the callers.
BeginnerQuick answer1 min read