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
-
They do not have return type.
-
They should be declared in the public section.
-
They cannot be inherited.
-
They can be virtual.
-
They have the same name as name of class.
D
Correct answer
Explanation
This is not the characteristic of constructor.
-
inheritance
-
association
-
encapsulation
-
nesting of class
-
binding class
D
Correct answer
Explanation
The process in which a class is defined within another class is called nesting of class.
-
single inheritance
-
hybrid inheritance
-
hierarchical inheritance
-
multilevel inheritance
-
multiple inheritance
D
Correct answer
Explanation
If a class C is derived from class B, which is derived from class A, all through public inheritance, then this type of inheritance is called multilevel inheritance.
-
default constructor
-
parametrised constructor
-
copy constructor
-
multi constructor
-
constructor overloading
C
Correct answer
Explanation
Copy constructor takes one argument.
-
virtual function
-
inline function
-
constructor
-
static member function
-
non-public constructor
A
Correct answer
Explanation
A virtual function is a member function that is declared within the base class, but redefined inside the derived class.
-
It can be declared both in the private and the public part of the class without altering the meaning.
-
It is called using the object of the class.
-
It does not belong to the class.
-
It is invoked like a normal function.
-
To access the data members of the class.
B
Correct answer
Explanation
It is not the characteristics of a friend function, since it is not called using the object of the class.
-
All the objects share the single copy of a static variable.
-
Static data members are always used in the non static member functions.
-
On the creation of the first object of the class a static variable is always initialised by zero.
-
The scope is only within the class, but its lifetime is throughout the program.
-
It can be accessed using their class names, the scope resolution operator and their member names.
B
Correct answer
Explanation
It is not the characteristic of static data member because static data members are always used in the static member functions.
-
Destructor cannot be overloaded.
-
Destructor can be inherited.
-
It is not possible to take the address of a destructor.
-
A destructor never accepts any argument nor does it return any value.
-
A destructor is invoked implicitly by the compiler when we exit from the program or block.
B
Correct answer
Explanation
It is not the characteristic of destructor because it cannot be inherited.
-
Public
-
Static
-
Protected
-
Private
-
Virtual
D
Correct answer
Explanation
Private visibility mode is used for data hiding.
-
Disk
-
RedBowl
-
Wash
-
Colour
-
Fill
B
Correct answer
Explanation
RedBowl defines an instance of class disk.
-
object
-
class
-
attribute
-
data member
-
member function
A
Correct answer
Explanation
A non-static function requires object to access data.
-
A class may inherit only one abstract class.
-
Abstract classes are instantiated directly.
-
An abstract class has at least one abstract method.
-
An abstract class without any implementation just looks like an interface.
-
Abstract classes are useful when creating hierarchies of classes that model reality.
B
Correct answer
Explanation
This is not true about abstract class because abstract classes are not instantiated directly.
-
manager functions
-
auxiliary functions
-
mutator functions
-
predicate functions
-
inspector functions
C
Correct answer
Explanation
Mutator functions, also known as implementors, are functions that change an object’s state or attributes.
-
cout << Book.price;
-
cout << Book(price);
-
cout << Book1.price;
-
cout << Book1(price);
-
cout >> Book1.price;
C
Correct answer
Explanation
This is the correct statement to display the object’s price field.
-
Virtual functions are member functions of a class.
-
Virtual function takes a different functionality in the derived class.
-
Virtual functions are declared with the keyword virtual.
-
Virtual functions are resolved during compile time.
-
Virtual function is a mechanism to implement the concept of polymorphism.
D
Correct answer
Explanation
It is not the characteristic of virtual function because virtual functions are resolved during run time.