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
-
Multilevel inheritance
-
Multiple inheritance
-
Single inheritance
-
Hierarchical inheritance
B
Correct answer
Explanation
Multiple inheritance is a form of inheritance in which there are one or more base classes which can be inherited onto the derived classes.
-
Operator overloading
-
Polymorphism
-
Inheritance
-
Function prototyping
D
Correct answer
Explanation
This is the property of C++, which enables functions having same name to be accessed multiple times by passing different number and type of arguments to the function.
-
Public inheritance
-
Multiple inheritance
-
Private inheritance
-
Multilevel inheritance
C
Correct answer
Explanation
In this mode of inheritance, public members of base class cannot be inherited as it becomes private to the derived class.
-
any member of the class instances
-
only static members of class instances
-
only integer values
-
none of the above
B
Correct answer
Explanation
Static member functions in C++ can access and modify only static data members of the class, not instance-specific members. This is because static functions are not bound to any particular object instance.
-
no arguments
-
one argument
-
two arguments
-
an object argument
A
Correct answer
Explanation
A default constructor is a constructor that takes no arguments. It's used to create objects without requiring any initialization parameters, initializing member variables to default values.
-
`Person
-
~Person
-
:Person
-
None of the above
B
Correct answer
Explanation
In C++, the destructor is named by prefixing a tilde (~) to the class name. For a class named Person, the destructor would be ~Person(), which is automatically called when the object is destroyed.
C
Correct answer
Explanation
C++ has three main types of constructors: default constructor (no parameters), parameterized constructor (with parameters), and copy constructor (creates object from another object of same class).
D
Correct answer
Explanation
A class is a blueprint or template, and you can create as many objects (instances) from it as you need, limited only by available memory. There is no theoretical limit imposed by the language itself.
-
reuse code
-
add functionality
-
both (1) and (2)
-
none of the above
C
Correct answer
Explanation
Inheritance allows derived classes to reuse code from base classes AND add new functionality, combining both benefits. This promotes code reuse and extensibility.
-
to reuse code
-
for component based programming
-
both (1) and (2)
-
none of the above
C
Correct answer
Explanation
Class libraries serve both purposes: they contain reusable code that programmers can use, and they support component-based programming by providing pre-built, tested components.
-
a user defined data type
-
a data type
-
a template for objects
-
all of the above
C
Correct answer
Explanation
A class is fundamentally a template or blueprint that defines the structure and behavior of objects. While it's also a user-defined data type, 'template for objects' best captures its role in creating instances.
-
private
-
public
-
protected
-
none of the above
B
Correct answer
Explanation
Methods (member functions) are typically declared public so they can be called from outside the class to perform operations on the object's data. Private methods exist but are less common.
D
Correct answer
Explanation
In C++, class definitions (like struct definitions) must end with a semicolon after the closing brace. This terminates the declaration statement.
-
DSACryptoServiceProvider
-
DSA
-
AesCryptoServiceProvider
-
SignatureDescription
-
ProtectedMemory
A
Correct answer
Explanation
This .NET cryptographic class defines a wrapper object to access the CSP implementation of the digital signature algorithm.
-
CryptographicAttributeObject
-
CryptographicAttributeObjectCollection
-
CryptographicAttributeObjectEnumerator
-
ProtectedData
-
CngKeyBlobFormat
B
Correct answer
Explanation
This .NET cryptographic class contains a group of CryptographicAttributeObject objects.