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. It represents and interprets the component behaviour.

  2. It encapsulates a request as an object.

  3. It avoids coupling the sender of a request to its receiver.

  4. It defines the creation of a class for which only a single instance can exist.

  5. It virtualises storage of entities in a persistent medium.

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

This pattern defines a representation along with an interpreter that uses the representation to interpret the behaviour of the components of the application.

Multiple choice
  1. It declares an interface to receive and act in extrinsic state.

  2. It is used to make an independent implementation for the abstract view.

  3. It separates the construction of a complex object from its representation.

  4. It specifies an abstract interface for creating parts of a product object.

  5. It constructs an object using the builder interface.

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

This pattern decouples an abstraction from its implementation, so that the two can vary independently.

Multiple choice
  1. It is used to specify the objects with their underlying representation.

  2. It encapsulates a request as an object.

  3. It avoids coupling the sender of a request to its receiver.

  4. It defines the creation of a class for which only a single instance can exist.

  5. It virtualises storage of entities in a persistent medium.

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

This pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

Multiple choice
  1. It falls under 'Structural' pattern.

  2. It maintains a reference to an object of type implementer.

  3. It defines an interface having members that will be implemented by RealSubject and Proxy class.

  4. This is a class which we want to use more efficiently by using proxy class.

  5. This is a class which holds the instance of RealSubject class and can access RealSubject class members as required.

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

Proxy pattern does not use such object reference. Bridge pattern is used for that.

Multiple choice
  1. It declares an interface common to all supported algorithms.

  2. A strategy interface is used to implement the class for the algorithms.

  3. It allows an object to alter its behaviour when its internal state changes.

  4. It maintains a reference to a strategy object.

  5. It may define an interface that lets strategy access its data.

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

It can alter the behaviour of the object. State pattern is used to alter the state of the object.

Multiple choice
  1. It connects two incompatible interfaces.

  2. It defines the domain-specific interface that a client uses.

  3. It collaborates with objects conforming to any interface.

  4. It adapts the interface adaptee to the target interface.

  5. It defines an existing interface that needs adapting.

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

This is incorrect.

Multiple choice
  1. It is used to combine two or more interfaces.

  2. There are domain-specific interface applied for the client.

  3. It defines an existing interface that needs adapting.

  4. It collaborates with objects conforming to the target interface.

  5. It extends the interface defined by abstraction.

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

It does not extend the interface for abstraction purpose.

Multiple choice
  1. It declares an interface for cloning itself.

  2. It implements an operation for cloning itself.

  3. It defines the abstraction interface.

  4. It creates a new object by asking a prototype to clone itself.

  5. It uses a prototype instance for each object.

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

Prototype pattern does not define any abstraction interface. Bridge pattern defines such interface.

Multiple choice
  1. It captures and externalises an object's internal state, so that the object can be restored to this state later.

  2. It protects against access of objects by other than the originator.

  3. It defines an object that encapsulates how a set of objects interact.

  4. The internal state of the memento is accessible by the originator only.

  5. It never operates on or examines the contents of a memento.

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

It does not encapsulate the set of objects. Mediator pattern is used for that.

Multiple choice
  1. There must be an interface to specify the state of the objects.

  2. It converts the interface of a class into another interface clients expect.

  3. The state of storage must be intrinsic.

  4. Not all Flyweight subclasses need to be shared.

  5. It uses sharing to support large numbers of fine-grained objects efficiently.

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

This pattern does not connect the two interfaces.

Multiple choice
  1. same as an abstract class

  2. a data type that cannot be instantiated

  3. a data type for which only the operations defined on it can be used, but none else

  4. all of the above

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

Abstract Data type :- It is defined as a user defined data type, specified by keyword 'abstract' & defines the variables & functions, these operations can only use the variables of this data type. So option (3) which says that Abstract data type for which only operations defined on it can be used is correct. Eg. stack data type Here operations defined are push & pop. So we can apply only these 2 operations on it.

Multiple choice
  1. 1 and 2 only

  2. 1 and 4 only

  3. 1, 2 and 4 only

  4. 1, 3 and 4 only

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

Object oriented programming languages necessarily have features like. Abstraction Encapsulation, inheritance with polymorphism but OOPL are also strongly-typed since there are restrictions on how operations involving values having different data types can be intermixed. Eg. two integers can be divided but one integer & one string can't.