Computer Knowledge
Object-Oriented Programming
2,239 Questions
Object-oriented programming questions test core computer science concepts like classes, inheritance, polymorphism, and encapsulation. The focus includes Java program structures, method overloading, and memory allocation for objects. This topic is essential for technical sections in various recruitment tests.
Java class definitionsMethod overriding rulesPolymorphism conceptsGeneric type parametersMemory allocation in objects
Object-Oriented Programming Questions
Which design pattern is used to define a family of algorithms, encapsulate each one, and make them interchangeable?
-
Strategy
-
Factory
-
Singleton
-
Decorator
A
Correct answer
Explanation
The Strategy design pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. This allows the algorithm to be selected at runtime.
Which design pattern is used to create a single instance of a class and provide a global point of access to that instance?
-
Singleton
-
Factory
-
Builder
-
Prototype
A
Correct answer
Explanation
The Singleton design pattern is used to create a single instance of a class and provide a global point of access to that instance.
Which design pattern is used to create objects without specifying the exact class of the object that will be created?
-
Factory
-
Builder
-
Prototype
-
Abstract Factory
A
Correct answer
Explanation
The Factory design pattern is used to create objects without specifying the exact class of the object that will be created.
Which design pattern is used to create a new object by copying an existing object?
-
Prototype
-
Builder
-
Factory
-
Singleton
A
Correct answer
Explanation
The Prototype design pattern is used to create a new object by copying an existing object.
Which design pattern is used to add new functionality to an existing object without changing its structure?
-
Decorator
-
Adapter
-
Proxy
-
Facade
A
Correct answer
Explanation
The Decorator design pattern is used to add new functionality to an existing object without changing its structure.
Which design pattern is used to convert the interface of a class into another interface that a client expects?
-
Adapter
-
Decorator
-
Proxy
-
Facade
A
Correct answer
Explanation
The Adapter design pattern is used to convert the interface of a class into another interface that a client expects.
Which design pattern is used to provide a unified interface to a set of interfaces in a subsystem?
-
Facade
-
Proxy
-
Decorator
-
Adapter
A
Correct answer
Explanation
The Facade design pattern is used to provide a unified interface to a set of interfaces in a subsystem.
Which design pattern is used to define an interface for creating objects, but lets subclasses decide which class to instantiate?
-
Abstract Factory
-
Factory
-
Builder
-
Prototype
A
Correct answer
Explanation
The Abstract Factory design pattern is used to define an interface for creating objects, but lets subclasses decide which class to instantiate.
Which design pattern is used to separate the construction of a complex object from its representation so that the same construction process can create different representations?
-
Builder
-
Factory
-
Prototype
-
Abstract Factory
A
Correct answer
Explanation
The Builder design pattern is used to separate the construction of a complex object from its representation so that the same construction process can create different representations.
Which design pattern is used to define a set of classes that share a common interface, allowing objects to be composed dynamically?
-
Composite
-
Decorator
-
Adapter
-
Proxy
A
Correct answer
Explanation
The Composite design pattern is used to define a set of classes that share a common interface, allowing objects to be composed dynamically.
Which design pattern is used to provide a surrogate or placeholder for another object to control access to it?
-
Proxy
-
Decorator
-
Adapter
-
Facade
A
Correct answer
Explanation
The Proxy design pattern is used to provide a surrogate or placeholder for another object to control access to it.
Which design pattern is used to provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation?
-
Iterator
-
Composite
-
Decorator
-
Adapter
A
Correct answer
Explanation
The Iterator design pattern is used to provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
Which design pattern is used to define an object that encapsulates how a set of objects interact?
-
Mediator
-
Observer
-
Command
-
Strategy
A
Correct answer
Explanation
The Mediator design pattern is used to define an object that encapsulates how a set of objects interact.
Which design pattern is used to define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically?
-
Observer
-
Mediator
-
Command
-
Strategy
A
Correct answer
Explanation
The Observer design pattern is used to define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Which design principle emphasizes the separation of concerns and promotes loose coupling?
-
Encapsulation
-
Inheritance
-
Polymorphism
-
Aggregation
A
Correct answer
Explanation
Encapsulation involves bundling data and methods together into distinct units, reducing dependencies and promoting loose coupling between components.