Computer Knowledge

Object-Oriented Programming

2,686 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 software design pattern is used to provide a uniform interface to a set of related objects?

  1. Factory Method

  2. Singleton

  3. Facade

  4. Builder

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

The Facade design pattern is used to provide a uniform interface to a set of related objects.

Multiple choice

What is a complexity class?

  1. A set of problems that can be solved by a Turing machine in a certain amount of time.

  2. A set of problems that can be solved by a Turing machine in a certain amount of space.

  3. A set of problems that can be solved by a Turing machine in a certain number of steps.

  4. A set of problems that can be solved by a Turing machine in a certain amount of memory.

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

A complexity class is a set of problems that can be solved by a Turing machine in a certain amount of time. The most common complexity classes are P, NP, and EXPTIME.

Multiple choice

Which design pattern is used to define a family of related objects?

  1. Factory Method

  2. Singleton

  3. Strategy

  4. Abstract Factory

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

The Abstract Factory pattern provides an interface for creating families of related objects without specifying their concrete classes.

Multiple choice

Which design pattern is commonly used to implement the Observer pattern?

  1. Adapter

  2. Composite

  3. Decorator

  4. Publisher-Subscriber

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

The Publisher-Subscriber pattern defines a one-to-many dependency between objects, where one object (publisher) notifies multiple objects (subscribers) about changes in its state.

Multiple choice

Which design pattern is used to provide a unified interface to a set of related classes?

  1. Facade

  2. Proxy

  3. Adapter

  4. Composite

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

The Facade pattern provides a unified interface to a set of related classes, simplifying their use and reducing coupling.

Multiple choice

Which design pattern is commonly used to implement the Singleton pattern?

  1. Factory Method

  2. Singleton

  3. Strategy

  4. Abstract Factory

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

The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance.

Multiple choice

Which of the following is NOT a common section found in API documentation?

  1. Introduction

  2. Function reference

  3. Class reference

  4. Troubleshooting guide

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

A troubleshooting guide is not typically a common section found in API documentation. It is more commonly found in user manuals or technical documentation, where it provides tips and solutions for common issues and problems.

Multiple choice

What is an initial object in a category?

  1. An object with a unique morphism from every other object

  2. An object with a unique morphism to every other object

  3. An object with no incoming morphisms

  4. An object with no outgoing morphisms

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

An initial object in a category is an object that has a unique morphism from every other object in the category, representing a universal starting point.

Multiple choice

What is a terminal object in a category?

  1. An object with a unique morphism from every other object

  2. An object with a unique morphism to every other object

  3. An object with no incoming morphisms

  4. An object with no outgoing morphisms

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

A terminal object in a category is an object that has a unique morphism to every other object in the category, representing a universal ending point.

Multiple choice

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

  1. Factory Method

  2. Strategy

  3. Observer

  4. Singleton

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

The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. This lets the algorithm vary independently from clients that use it.

Multiple choice

What is the purpose of the Observer design pattern?

  1. To define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

  2. To create a single instance of a class and provide a global point of access to that instance.

  3. To provide a way to add or remove objects from a collection dynamically.

  4. To define an interface for creating objects, but let subclasses decide which class to instantiate.

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

The Observer pattern defines 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 pattern is used to create a single instance of a class and provide a global point of access to that instance?

  1. Factory Method

  2. Strategy

  3. Observer

  4. Singleton

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

The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance.

Multiple choice

What is the purpose of the Factory Method design pattern?

  1. To define a family of algorithms, encapsulate each one, and make them interchangeable.

  2. To create a single instance of a class and provide a global point of access to that instance.

  3. To provide a way to add or remove objects from a collection dynamically.

  4. To define an interface for creating objects, but let subclasses decide which class to instantiate.

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

The Factory Method pattern defines an interface for creating objects, but lets subclasses decide which class to instantiate.

Multiple choice

What is the purpose of the Adapter design pattern?

  1. To convert the interface of a class into another interface clients expect.

  2. To define a family of algorithms, encapsulate each one, and make them interchangeable.

  3. To provide a way to add or remove objects from a collection dynamically.

  4. To define an interface for creating objects, but let subclasses decide which class to instantiate.

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

The Adapter pattern converts the interface of a class into another interface clients expect. This lets classes work together that couldn't otherwise because of incompatible interfaces.

Multiple choice

Which design pattern is used to define a family of related classes and provide a way to create objects without specifying their exact class?

  1. Factory Method

  2. Abstract Factory

  3. Builder

  4. Prototype

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

The Abstract Factory pattern provides an interface for creating families of related objects without specifying their concrete classes.