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 commonly used to dynamically add or remove responsibilities from an object?

  1. Facade

  2. Composite

  3. Decorator

  4. Proxy

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

The Decorator pattern allows the dynamic addition or removal of responsibilities from an object, providing a flexible way to modify the behavior of an object at runtime.

Multiple choice

Which design pattern provides a way to define a family of algorithms, encapsulate them, and make them interchangeable?

  1. Factory Method

  2. Strategy

  3. Singleton

  4. Decorator

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

The Strategy design pattern allows you to define a family of algorithms, encapsulate each one, and make them interchangeable. This promotes flexibility and code reuse.

Multiple choice

Which design pattern allows you to add new functionality to an existing class without modifying its source code?

  1. Factory Method

  2. Strategy

  3. Decorator

  4. Adapter

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

The Decorator design pattern allows you to add new functionality to an existing class without modifying its source code, providing a flexible way to extend the behavior of objects.

Multiple choice

Which design pattern provides a way to create objects without specifying the exact class to instantiate?

  1. Factory Method

  2. Strategy

  3. Singleton

  4. Builder

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

The Factory Method design pattern provides a way to create objects without specifying the exact class to instantiate, allowing for flexible object creation and decoupling.

Multiple choice

Which design pattern allows you to create a single instance of a class and ensure that it is accessed globally?

  1. Factory Method

  2. Strategy

  3. Singleton

  4. Builder

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

The Singleton design pattern allows you to create a single instance of a class and ensure that it is accessed globally, promoting resource optimization and controlled access.

Multiple choice

Which design pattern allows you to create complex objects step-by-step, using a series of smaller, simpler steps?

  1. Factory Method

  2. Strategy

  3. Builder

  4. Adapter

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

The Builder design pattern allows you to create complex objects step-by-step, using a series of smaller, simpler steps, promoting flexibility and code readability.

Multiple choice

Which design pattern allows you to convert the interface of a class into another interface that clients expect?

  1. Factory Method

  2. Strategy

  3. Adapter

  4. Builder

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

The Adapter design pattern allows you to convert the interface of a class into another interface that clients expect, promoting compatibility and interoperability.

Multiple choice

Which design pattern allows you to create objects that can be composed into larger objects, providing a tree-like structure?

  1. Factory Method

  2. Strategy

  3. Composite

  4. Builder

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

The Composite design pattern allows you to create objects that can be composed into larger objects, providing a tree-like structure and promoting flexibility and code reusability.

Multiple choice

Which programming paradigm emphasizes the use of objects and classes to represent real-world entities?

  1. Procedural Programming

  2. Object-Oriented Programming

  3. Functional Programming

  4. Logic Programming

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

Object-Oriented Programming (OOP) emphasizes the use of objects and classes to represent real-world entities, allowing for modularity, encapsulation, and code reusability.

Multiple choice

What is the term for an individual object or instance that possesses a universal property?

  1. Particular

  2. Instance

  3. Example

  4. Token

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

Particulars are individual objects or instances that possess universal properties. For example, 'Socrates' is a particular human being.

Multiple choice

In Type Theory, what is a type?

  1. A collection of objects with similar characteristics

  2. A set of values that can be assigned to a variable

  3. A classification system for organizing data

  4. A function that maps inputs to outputs

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

In Type Theory, a type is a collection of objects that share certain properties or characteristics.

Multiple choice

What is the Curry-Howard correspondence?

  1. A connection between types and propositions

  2. A method for type inference

  3. A technique for program verification

  4. An algorithm for type checking

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

The Curry-Howard correspondence establishes a relationship between types in Type Theory and propositions in Logic.

Multiple choice

Which type theory introduces dependent types?

  1. Simple type theory

  2. Dependent type theory

  3. Intuitionistic type theory

  4. Constructive type theory

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

Dependent type theory extends simple type theory by allowing types to depend on values or expressions.

Multiple choice

What is the this keyword in JavaScript?

  1. It refers to the current object

  2. It refers to the global object

  3. It refers to the function that is being called

  4. It refers to the parent object

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

The this keyword in JavaScript refers to the current object. The value of this depends on how the function is called. When a function is called as a method of an object, this refers to that object. When a function is called as a standalone function, this refers to the global object.

Multiple choice

Which of the following is not a valid way to define a JavaScript object?

  1. const object = {};

  2. const object = new Object();

  3. const object = { property: value };

  4. const object = [property: value]

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

The const object = [property: value] syntax is not a valid way to define a JavaScript object. The correct syntax is const object = {};, const object = new Object();, or const object = { property: value };.