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
  1. When the class has no other constructors

  2. When you define at least one constructor with at least one parameter

  3. When you define at least one constructor

  4. none of the above

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

The Java compiler automatically provides a default, no-argument constructor only if no other constructors are explicitly defined in the class. If you write any constructor yourself, whether it has parameters or not, the compiler will not generate the default constructor.

Multiple choice
  1. myClass

  2. The_Classiest_Class

  3. MyClassyClass

  4. aniketsclasstoendallclasses

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

Java class naming conventions dictate using UpperCamelCase (PascalCase), where the first letter of each word is capitalized, and no underscores or special characters are used. 'MyClassyClass' perfectly adheres to this standard.

Multiple choice
  1. Has a specific function

  2. Has a general function

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

In biology, specialized cells or tissues are those that have developed unique structures to perform a specific function. Unlike general cells, they are highly adapted to carry out one particular job efficiently.

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.