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

Multiple choice

Which design pattern is used to define a family of algorithms, encapsulate each one, and make them interchangeable?

  1. Strategy

  2. Factory

  3. Singleton

  4. Decorator

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

Which design pattern is used to create a single instance of a class and provide a global point of access to that instance?

  1. Singleton

  2. Factory

  3. Builder

  4. Prototype

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

Which design pattern is used to create objects without specifying the exact class of the object that will be created?

  1. Factory

  2. Builder

  3. Prototype

  4. Abstract Factory

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

Which design pattern is used to create a new object by copying an existing object?

  1. Prototype

  2. Builder

  3. Factory

  4. Singleton

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Prototype design pattern is used to create a new object by copying an existing object.

Multiple choice

Which design pattern is used to add new functionality to an existing object without changing its structure?

  1. Decorator

  2. Adapter

  3. Proxy

  4. Facade

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Decorator design pattern is used to add new functionality to an existing object without changing its structure.

Multiple choice

Which design pattern is used to convert the interface of a class into another interface that a client expects?

  1. Adapter

  2. Decorator

  3. Proxy

  4. Facade

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Adapter design pattern is used to convert the interface of a class into another interface that a client expects.

Multiple choice

Which design pattern is used to provide a unified interface to a set of interfaces in a subsystem?

  1. Facade

  2. Proxy

  3. Decorator

  4. Adapter

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Facade design pattern is used to provide a unified interface to a set of interfaces in a subsystem.

Multiple choice

Which design pattern is used to define an interface for creating objects, but lets subclasses decide which class to instantiate?

  1. Abstract Factory

  2. Factory

  3. Builder

  4. Prototype

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

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?

  1. Builder

  2. Factory

  3. Prototype

  4. Abstract Factory

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

Which design pattern is used to define a set of classes that share a common interface, allowing objects to be composed dynamically?

  1. Composite

  2. Decorator

  3. Adapter

  4. Proxy

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

Which design pattern is used to provide a surrogate or placeholder for another object to control access to it?

  1. Proxy

  2. Decorator

  3. Adapter

  4. Facade

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Proxy design pattern is used to provide a surrogate or placeholder for another object to control access to it.

Multiple choice

Which design pattern is used to provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation?

  1. Iterator

  2. Composite

  3. Decorator

  4. Adapter

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

Which design pattern is used to define an object that encapsulates how a set of objects interact?

  1. Mediator

  2. Observer

  3. Command

  4. Strategy

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Mediator design pattern is used to define an object that encapsulates how a set of objects interact.

Multiple choice

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?

  1. Observer

  2. Mediator

  3. Command

  4. Strategy

Reveal answer Fill a bubble to check yourself
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.

Multiple choice

Which design principle emphasizes the separation of concerns and promotes loose coupling?

  1. Encapsulation

  2. Inheritance

  3. Polymorphism

  4. Aggregation

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Encapsulation involves bundling data and methods together into distinct units, reducing dependencies and promoting loose coupling between components.