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
-
Class A is derived in class B
-
Method of class A is implemented in class B
-
Class B is derived in class A
-
Class A and class B are same class
-
Class B cannot be derived in class A
C
Correct answer
Explanation
This is the correct option as colon operator is used in C# to inherit any class in an existing class.
-
Object type
-
Class type
-
Interfaces
-
Delegates
-
String type
A
Correct answer
Explanation
This type is used in C# when a value is boxed, which means a value refers to implicitly converting any value type to the type object.
-
Interfaces
-
Class
-
Object
-
Delegates
-
String
D
Correct answer
Explanation
This data type in C# is the type-safe and secure version of function pointers.
-
Declare the method outside the base class only.
-
Declare the method in the derived class only.
-
Declare the method in both base class and derived class.
-
Declare the method in the base class with the keyword 'Hide'.
-
Delete the method declared in base and derived class.
C
Correct answer
Explanation
This is the correct option as the method is declared in both base and derived class by default the derived version of the method is only accessible but to access the base class method the following changes has to be done in the program.
DerivedClass test = new DerivedClass();
((BaseClass)test).TestMethod();
The above code will only access the base class method of a class.
-
single inheritance
-
multilevel inheritance
-
polymorphism
-
message passing
-
multiple inheritance
B
Correct answer
Explanation
Multilevel inheritance derives a class from another derived class.
-
shadowing
-
function overriding
-
function overloading
-
function definition
-
operator overloading
A
Correct answer
Explanation
Shadowing redefines the entire element.
-
mid value
-
class limit
-
class mark
-
class size
-
class frequency
D
Correct answer
Explanation
Class size is the difference between the upper boundary and the lower boundary of the class.
-
empty class
-
modal class
-
open-ended class
-
close-ended class
-
class frequency
C
Correct answer
Explanation
When one end of the class is not specified, it is called open-ended class.
-
Inheritance
-
Polymorphism
-
Classes
-
Encapsulation
B
Correct answer
Explanation
Polymorphism is an important OOP concept. An operation may exhibit different behaviour in different instances.
-
Classes
-
Polymorphism
-
Inheritance
-
Encapsulation
C
Correct answer
Explanation
Inheritance is the property of C++ that allows the reusing of any class into another class without modifying it.
-
protected
-
public
-
private
-
not inherited
C
Correct answer
Explanation
The protected data members of a class become private when privately inherited in the derived class to maintain data hiding property of OOP.
-
Member function
-
Static member function
-
Inline function
-
Recursive function
B
Correct answer
Explanation
A static member function can be called using the class name instead of its objects and it makes the use of static data members only.
-
Structure
-
Union
-
Enumeration
-
Function
D
Correct answer
Explanation
Function is a derived data type in C++ which is used to perform some predefined tasks.
-
Object
-
Class
-
Constructor
-
Destructor
C
Correct answer
Explanation
Constructor is a special kind of member function, whose task is to initialize the object of its class. This is implicitly called when the object of the class is created.
-
Fstream
-
Ifstream
-
Ofstream
-
Fstreambase
A
Correct answer
Explanation
This stream class inherits all the functions from istream and ostream classes through iostream, allowing both I/O functions.