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
-
To stop overriding
-
To stop its implementation
-
To stop inheritance
-
None of these
D
Correct answer
Explanation
Explanation: We seal the class/method to stop its inheritance so that it could not be further inherited.
-
Public
-
Private
-
Static
-
Protected
C
Correct answer
Explanation
It isĀ Static because this is a modifier which modifies/changes the present state.
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.
-
We can't declare Interface like this
-
We can't give body to Interface like this
-
We can't give body to things like methods in the Interface like this
-
None of the above
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.
-
We can make Singleton class by making a private constructor of that class.
-
Static initialization is suitable for multiple threaded Singleton class.
-
Singleton class is used to save state and storing caches.
-
All of the above.
-
Only (1) and (3).
D
Correct answer
Explanation
All are the correct statements about Singleton class.
-
It comes under the category of Creational design Pattern.
-
In this pattern, a limited number of state combinations exist in an object.
-
Prototype pattern is used to reduce the database calls during database operations.
-
All of the above
-
Both (1) and (3)
D
Correct answer
Explanation
All of the above are the correct statements about Prototype design pattern.
-
Singleton pattern reduces the potential for parallelism within a program.
-
Using this pattern, the unit testing is more difficult.
-
Singleton can be lazy loaded.
-
Both (1) and(2).
-
None of the above.
D
Correct answer
Explanation
These are the disadvantages of using Singleton Pattern in .Net.
-
This pattern provides an interface to other objects by creating a wrapper class as the proxy.
-
It provides the thread-safe feature to an existing class without changing the existing class's code.
-
This pattern is used to construct a complex object.
-
This pattern is used in web services.
-
None of the above.
C
Correct answer
Explanation
Proxy pattern does not provide any construction of the object as it provides the representation for the pre-existing object.
-
It creates an has-a relationship.
-
It creates an is-a relationship.
-
This implementation is used when a class with an incompatible method needs to be used with another class.
-
Both (2) and (3).
-
None of the above.
D
Correct answer
Explanation
These are the incorrect statements about Adapter implementation using composition.
-
Singleton class provides interface inheritance.
-
Singleton class has static initialization.
-
Singleton class can be extended into a factory pattern.
-
All of the above.
-
Only (1) and (2).
D
Correct answer
Explanation
All the above statements describe the usability of the Singleton class.
-
In Shallow Cloning, the copy of an object copies the elements and everything directly or indirectly referenced by the elements.
-
In a Shallow copy, it copies all reference types or value types.
-
In this cloning, only the parent object is cloned.
-
In this cloning, the references in the new object point to the same objects that the references in the original object points to.
-
Both (1) and (3).
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.
-
It has step by step construction of a complex object.
-
This pattern does not provide any concrete class for the dependent objects.
-
This pattern allows the type of objects to be instantiated at run time.
-
All of the above.
-
Both (2) and (3).
B
Correct answer
Explanation
Abstract factory pattern encapsulate the group of factories in an interface with a common theme.
-
It declares an interface to define the methods for the client.
-
Client code should not be concerned about the details of the implementations.
-
It provides a way to access the elements of aggregate objects sequentially without exposing its representation.
-
All of the above.
-
Both (1) and (3).
D
Correct answer
Explanation
These are the correct statements about Iterator pattern.
-
In this cloning, the copy of an object copies the elements and everything directly or indirectly referenced by the elements.
-
In a deep copy, it copies all reference types or value types.
-
In this cloning, only the parent object is cloned.
-
In this cloning, the references in the new object point to the same objects that the references in the original object points to.
-
Both (1) and (2).
E
Correct answer
Explanation
These are the correct statements about Deep cloning.
-
This pattern specifies the class creation for a particular object only.
-
It is useful for exposing read-only data.
-
This pattern virtualises storage of entities in a persistent medium.
-
The static methods do not rely on instance data.
-
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.
C
Correct answer
Explanation
Singleton pattern does not store entities for the persistence medium.