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 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.

Multiple choice

Which design pattern is commonly used to provide flexibility and extensibility by allowing new behaviors to be added without modifying existing code?

  1. Singleton

  2. Factory

  3. Strategy

  4. Builder

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

The Strategy pattern allows different algorithms or behaviors to be selected at runtime, providing flexibility and extensibility without modifying the core logic.

Multiple choice

Which programming paradigm is known for its encapsulation, inheritance, and polymorphism features?

  1. Imperative Programming

  2. Declarative Programming

  3. Object-Oriented Programming

  4. Functional Programming

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

Object-oriented programming organizes code into objects, which contain both data and methods, and allows for inheritance and polymorphism.

Multiple choice

Which of the following is a common software design pattern?

  1. Singleton

  2. Factory

  3. Observer

  4. All of the above

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

Singleton, Factory, and Observer are all common software design patterns. Design patterns are reusable solutions to commonly occurring problems in software design.

Multiple choice

Which of the following is NOT a common design pattern?

  1. Factory Method

  2. Singleton

  3. Observer

  4. Composite

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

Composite is not a design pattern; it is a structural pattern that describes how objects can be composed into larger structures.

Multiple choice

What is the main principle behind object-oriented programming?

  1. Encapsulation

  2. Inheritance

  3. Polymorphism

  4. Abstraction

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

Abstraction is the fundamental principle of object-oriented programming, which involves hiding the implementation details of an object and exposing only its essential characteristics.

Multiple choice

Which of the following is NOT a common software design anti-pattern?

  1. Spaghetti Code

  2. God Object

  3. Big Ball of Mud

  4. Singleton

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

Singleton is not an anti-pattern; it is a design pattern that restricts the instantiation of a class to only one object.

Multiple choice

Which of the following is NOT a common code smell?

  1. Long methods.

  2. Duplicated code.

  3. Unused code.

  4. Well-commented code.

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

Well-commented code is generally not considered a code smell. In fact, it is often seen as a good practice to add comments to code to make it more readable and understandable.

Multiple choice

What are the different types of casting calls?

  1. Open calls

  2. Closed calls

  3. Targeted calls

  4. All of the above

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

There are three main types of casting calls: open calls, closed calls, and targeted calls. Open calls are open to anyone who wants to audition, while closed calls are only open to actors who have been invited. Targeted calls are open to actors who have specific skills or experience that are relevant to the project.

Multiple choice

Which of the following is NOT a fundamental principle of OOP?

  1. Encapsulation

  2. Inheritance

  3. Polymorphism

  4. Modularity

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

Modularity is not a fundamental principle of OOP. The fundamental principles of OOP are encapsulation, inheritance, and polymorphism.