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. single inheritance

  2. hybrid inheritance

  3. hierarchical inheritance

  4. multilevel inheritance

  5. multiple inheritance

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

 

Multiple choice
  1. It can be declared both in the private and the public part of the class without altering the meaning.

  2. It is called using the object of the class.

  3. It does not belong to the class.

  4. It is invoked like a normal function.

  5. To access the data members of the class.

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

It is not the characteristics of a friend function, since it is not called using the object of the class.

Multiple choice
  1. All the objects share the single copy of a static variable.

  2. Static data members are always used in the non static member functions.

  3. On the creation of the first object of the class a static variable is always initialised by zero.

  4. The scope is only within the class, but its lifetime is throughout the program.

  5. It can be accessed using their class names, the scope resolution operator and their member names.

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

Multiple choice
  1. Destructor cannot be overloaded.

  2. Destructor can be inherited.

  3. It is not possible to take the address of a destructor.

  4. A destructor never accepts any argument nor does it return any value.

  5. A destructor is invoked implicitly by the compiler when we exit from the program or block.

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

It is not the characteristic of destructor because it cannot be inherited.

Multiple choice
  1. A class may inherit only one abstract class.

  2. Abstract classes are instantiated directly.

  3. An abstract class has at least one abstract method.

  4. An abstract class without any implementation just looks like an interface.

  5. Abstract classes are useful when creating hierarchies of classes that model reality.

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

This is not true about abstract class because abstract classes are not instantiated directly.

Multiple choice
  1. cout << Book.price;

  2. cout << Book(price);

  3. cout << Book1.price;

  4. cout << Book1(price);

  5. cout >> Book1.price;

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

This is the correct statement to display the object’s price field.

Multiple choice
  1. Virtual functions are member functions of a class.

  2. Virtual function takes a different functionality in the derived class.

  3. Virtual functions are declared with the keyword virtual.

  4. Virtual functions are resolved during compile time.

  5. Virtual function is a mechanism to implement the concept of polymorphism.

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

It is not the characteristic of virtual function because virtual functions are resolved during run time.