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

Multiple choice
  1. Tagged value

  2. Constraint

  3. Stereotype

  4. Object-oriented system

  5. None of these

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. Destructor must have the same name as the class preceded by a tilde (~).

  2. Destructor has a return type.

  3. Destructor cannot take arguments; so it cannot be overloaded.

  4. There can be only one destructor in each class.

  5. Destructor cannot be inherited.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This is not the correct characteristic of the destructor function as it cannot return any value.

Multiple choice
  1. Parameterized constructor

  2. Copy constructor

  3. Default constructor

  4. Constructor overloading

  5. Destructor

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. It is compulsorily required in every program.

  2. It is used to access data members of a class.

  3. It is used to initialise the object of a class.

  4. It is used to avoid any confusion when overloaded constructors are used.

  5. It is of no use.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct option as default constructor is used to initialise the object of a class.

Multiple choice
  1. It should be declared in the public section.

  2. It can be invoked automatically when the objects are created.

  3. It cannot return any value not even void type.

  4. Constructors can be virtual.

  5. Constructors can make implicit calls to the operators new and delete when memory allocation is required.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. Default constructor

  2. Parameterized constructor

  3. Copy constructor

  4. Overloaded constructor

  5. Constructor with default value

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. Derived constructor:Base constructor:

  2. Base constructor:Derived constructor:

  3. Default constructor:Base constructor:

  4. Derived constructor:Default constructor:

  5. Base constructor:Base constructor:

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. It avoids creating private members in a class.

  2. Constuctor functions are automatically invoked when objects are created.

  3. It avoids creating friend function in a class.

  4. It avoids creating destructor function in a class.

  5. It avoids creating pointers to objects.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This is the main advantage of using a constructor function in a class.

Multiple choice
  1. There can be only one destructor function for a class.

  2. Destructor functions are not invoked automatically when the objects are destroyed.

  3. Arguments can be provided to a destructor.

  4. A destructor function can return value.

  5. It can be declared in the private section of a class.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is the only one special property of a destructor function.