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
-
Tagged value
-
Constraint
-
Stereotype
-
Object-oriented system
-
None of these
C
Correct answer
Explanation
A stereotype extends the vocabulary of the UML, allowing one to create new kinds of building blocks that are derived from existing ones but that are specific to one's problems.
-
Destructor must have the same name as the class preceded by a tilde (~).
-
Destructor has a return type.
-
Destructor cannot take arguments; so it cannot be overloaded.
-
There can be only one destructor in each class.
-
Destructor cannot be inherited.
B
Correct answer
Explanation
This is not the correct characteristic of the destructor function as it cannot return any value.
-
Parameterized constructor
-
Copy constructor
-
Default constructor
-
Constructor overloading
-
Destructor
C
Correct answer
Explanation
This type of constructor is a special member function that is invoked by the C++ compiler without any arguments for initialising the objects of a class.
-
private
-
protected
-
public
-
private protected
-
default
C
Correct answer
Explanation
This is the correct option as constructor function should be declared in the public section only so that it can be accessible outside the class.
-
100 and 10
-
100 and 200
-
10 and 100
-
200 and 100
-
No values are assigned.
A
Correct answer
Explanation
This is correct assignment as with the object creation, only one argument is passed and another value assigned is the default argument.
-
It is compulsorily required in every program.
-
It is used to access data members of a class.
-
It is used to initialise the object of a class.
-
It is used to avoid any confusion when overloaded constructors are used.
-
It is of no use.
C
Correct answer
Explanation
This is the correct option as default constructor is used to initialise the object of a class.
-
Copy constructor
-
Default constructor
-
Constructor with default arguments
-
Destructor
-
Parameterized constructor
D
Correct answer
Explanation
This is a special member function that is executed when an object of that class is destroyed.
-
It should be declared in the public section.
-
It can be invoked automatically when the objects are created.
-
It cannot return any value not even void type.
-
Constructors can be virtual.
-
Constructors can make implicit calls to the operators new and delete when memory allocation is required.
D
Correct answer
Explanation
This is not the characteristic of a constructor as constructors cannot be virtual because virtual keyword creates a single copy of the function to derived class.
-
Static variable
-
Pointer variable
-
Reference variable
-
new
-
delete
C
Correct answer
Explanation
This variable can be used as an argument to the copy constructor as argument can only be passed by reference in a copy constructor.
-
Friend function
-
Inline function
-
Default constructor
-
this pointer
-
Static member function
C
Correct answer
Explanation
A default constructor is created to create and initialise objects of the same class.
-
Default constructor
-
Parameterized constructor
-
Copy constructor
-
Overloaded constructor
-
Constructor with default value
B
Correct answer
Explanation
This type of constructor function should be used to initialise the various data elements of different objects with different values when they are created.
-
Derived constructor:Base constructor:
-
Base constructor:Derived constructor:
-
Default constructor:Base constructor:
-
Derived constructor:Default constructor:
-
Base constructor:Base constructor:
B
Correct answer
Explanation
This is the correct output of the above C++ code. If the constructor function is used in both base and derived classes, then always the base constructor function would be executed first and then derived constructor.
-
It avoids creating private members in a class.
-
Constuctor functions are automatically invoked when objects are created.
-
It avoids creating friend function in a class.
-
It avoids creating destructor function in a class.
-
It avoids creating pointers to objects.
B
Correct answer
Explanation
This is the main advantage of using a constructor function in a class.
-
There can be only one destructor function for a class.
-
Destructor functions are not invoked automatically when the objects are destroyed.
-
Arguments can be provided to a destructor.
-
A destructor function can return value.
-
It can be declared in the private section of a class.
A
Correct answer
Explanation
This is the only one special property of a destructor function.
-
explicit call
-
implicit call
-
pointer call
-
reference call
-
call by value
A
Correct answer
Explanation
This method of calling constructor function is called as explicit call.