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
-
It represents and interprets the component behaviour.
-
It encapsulates a request as an object.
-
It avoids coupling the sender of a request to its receiver.
-
It defines the creation of a class for which only a single instance can exist.
-
It virtualises storage of entities in a persistent medium.
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.
-
It declares an interface to receive and act in extrinsic state.
-
It is used to make an independent implementation for the abstract view.
-
It separates the construction of a complex object from its representation.
-
It specifies an abstract interface for creating parts of a product object.
-
It constructs an object using the builder interface.
B
Correct answer
Explanation
This pattern decouples an abstraction from its implementation, so that the two can vary independently.
-
It is used to specify the objects with their underlying representation.
-
It encapsulates a request as an object.
-
It avoids coupling the sender of a request to its receiver.
-
It defines the creation of a class for which only a single instance can exist.
-
It virtualises storage of entities in a persistent medium.
A
Correct answer
Explanation
This pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
-
It falls under 'Structural' pattern.
-
It maintains a reference to an object of type implementer.
-
It defines an interface having members that will be implemented by RealSubject and Proxy class.
-
This is a class which we want to use more efficiently by using proxy class.
-
This is a class which holds the instance of RealSubject class and can access RealSubject class members as required.
B
Correct answer
Explanation
Proxy pattern does not use such object reference. Bridge pattern is used for that.
-
It declares an interface common to all supported algorithms.
-
A strategy interface is used to implement the class for the algorithms.
-
It allows an object to alter its behaviour when its internal state changes.
-
It maintains a reference to a strategy object.
-
It may define an interface that lets strategy access its data.
C
Correct answer
Explanation
It can alter the behaviour of the object. State pattern is used to alter the state of the object.
-
It connects two incompatible interfaces.
-
It defines the domain-specific interface that a client uses.
-
It collaborates with objects conforming to any interface.
-
It adapts the interface adaptee to the target interface.
-
It defines an existing interface that needs adapting.
-
It is used to combine two or more interfaces.
-
There are domain-specific interface applied for the client.
-
It defines an existing interface that needs adapting.
-
It collaborates with objects conforming to the target interface.
-
It extends the interface defined by abstraction.
E
Correct answer
Explanation
It does not extend the interface for abstraction purpose.
-
It declares an interface for cloning itself.
-
It implements an operation for cloning itself.
-
It defines the abstraction interface.
-
It creates a new object by asking a prototype to clone itself.
-
It uses a prototype instance for each object.
C
Correct answer
Explanation
Prototype pattern does not define any abstraction interface. Bridge pattern defines such interface.
-
This pattern defines a one-to-many dependency between objects.
-
It collaborates with objects conforming to the target interface.
-
It knows its observers.
-
An updatable interface is needed for all the objects to be notified.
-
It stores state of interest to ConcreteObserver.
-
It captures and externalises an object's internal state, so that the object can be restored to this state later.
-
It protects against access of objects by other than the originator.
-
It defines an object that encapsulates how a set of objects interact.
-
The internal state of the memento is accessible by the originator only.
-
It never operates on or examines the contents of a memento.
C
Correct answer
Explanation
It does not encapsulate the set of objects. Mediator pattern is used for that.
-
There must be an interface to specify the state of the objects.
-
It converts the interface of a class into another interface clients expect.
-
The state of storage must be intrinsic.
-
Not all Flyweight subclasses need to be shared.
-
It uses sharing to support large numbers of fine-grained objects efficiently.
B
Correct answer
Explanation
This pattern does not connect the two interfaces.
-
ProtectedData
-
AsymmetricSignatureFormatter
-
RSAPKCS1KeyExchangeFormatter
-
RSAPKCS1SignatureFormatter
-
RSAPKCS1SignatureDeformatter
D
Correct answer
Explanation
This .NET cryptographic class creates an RSA PKCS#1 version signature.
-
SHA256CryptoServiceProvider
-
SHA256
-
SHA256Cng
-
SHA384CryptoServiceProvider
-
ProtectedData
A
Correct answer
Explanation
This .NET cryptographic class defines a wrapper object to access the CSP implementation of the secure hash algorithm 256 algorithm.
-
same as an abstract class
-
a data type that cannot be instantiated
-
a data type for which only the operations defined on it can be used, but none else
-
all of the above
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.
-
1 and 2 only
-
1 and 4 only
-
1, 2 and 4 only
-
1, 3 and 4 only
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.