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

  2. No

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

Explanation: We can't create the object of an abstract class because these are the classes which get its implementation in the classes where these are used.

Multiple choice
  1. We can't declare Interface like this

  2. We can't give body to Interface like this

  3. We can't give body to things like methods in the Interface like this

  4. None of the above

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

Explanation: Interfaces do not have implementation within them. Instead, they are used as such and are given body wherever they are implemented. So, all the working done in the Sum() must not be there for the time being it is in the Interface ISum.

Multiple choice
  1. It comes under the category of Creational design Pattern.

  2. In this pattern, a limited number of state combinations exist in an object.

  3. Prototype pattern is used to reduce the database calls during database operations.

  4. All of the above

  5. Both (1) and (3)

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

All of the above are the correct statements about Prototype design pattern.

Multiple choice
  1. Singleton pattern reduces the potential for parallelism within a program.

  2. Using this pattern, the unit testing is more difficult.

  3. Singleton can be lazy loaded.

  4. Both (1) and(2).

  5. None of the above.

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

These are the disadvantages of using Singleton Pattern in .Net.

Multiple choice
  1. This pattern provides an interface to other objects by creating a wrapper class as the proxy.

  2. It provides the thread-safe feature to an existing class without changing the existing class's code.

  3. This pattern is used to construct a complex object.

  4. This pattern is used in web services.

  5. None of the above.

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

Proxy pattern does not provide any construction of the object as it provides the representation for the pre-existing object.

Multiple choice
  1. It creates an has-a relationship.

  2. It creates an is-a relationship.

  3. This implementation is used when a class with an incompatible method needs to be used with another class.

  4. Both (2) and (3).

  5. None of the above.

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

These are the incorrect statements about Adapter implementation using composition.

Multiple choice
  1. Singleton class provides interface inheritance.

  2. Singleton class has static initialization.

  3. Singleton class can be extended into a factory pattern.

  4. All of the above.

  5. Only (1) and (2).

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

All the above statements describe the usability of the Singleton class.

Multiple choice
  1. In Shallow Cloning, the copy of an object copies the elements and everything directly or indirectly referenced by the elements.

  2. In a Shallow copy, it copies all reference types or value types.

  3. In this cloning, only the parent object is cloned.

  4. In this cloning, the references in the new object point to the same objects that the references in the original object points to.

  5. Both (1) and (3).

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

Shallow Cloning does not copy the objects that the references refer to. This is only possible in case of deep cloning.

Multiple choice
  1. It has step by step construction of a complex object.

  2. This pattern does not provide any concrete class for the dependent objects.

  3. This pattern allows the type of objects to be instantiated at run time.

  4. All of the above.

  5. Both (2) and (3).

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

Abstract factory pattern encapsulate the group of factories in an interface with a common theme.

Multiple choice
  1. It declares an interface to define the methods for the client.

  2. Client code should not be concerned about the details of the implementations.

  3. It provides a way to access the elements of aggregate objects sequentially without exposing its representation.

  4. All of the above.

  5. Both (1) and (3).

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

These are the correct statements about Iterator pattern.

Multiple choice
  1. In this cloning, the copy of an object copies the elements and everything directly or indirectly referenced by the elements.

  2. In a deep copy, it copies all reference types or value types.

  3. In this cloning, only the parent object is cloned.

  4. In this cloning, the references in the new object point to the same objects that the references in the original object points to.

  5. Both (1) and (2).

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

These are the correct statements about Deep cloning.

Multiple choice
  1. This pattern specifies the class creation for a particular object only.

  2. It is useful for exposing read-only data.

  3. This pattern virtualises storage of entities in a persistent medium.

  4. The static methods do not rely on instance data.

  5. If this is the first call to the method that returns the instance, the Singleton creates an instance, populates it with any required data and returns that instance.

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

Singleton pattern does not store entities for the persistence medium.