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. We declare any function to be static by putting keyword <b style="mso-bidi-font-weight:normal"><i style="mso-bidi-font-style:normal">static before the function declaration in the class.

  2. A static member can access all the members of the same class.

  3. Static member function is invoked using the class name, instead of object's name

  4. None of the above

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

This option is correct because given statement is incorrect as static member function can access only static members (functions or variables) of the same class.

Multiple choice
  1. There is the only one copy of the data member, maintained for the entire class.

  2. Its lifetime is same as lifetime of the object of the class

  3. Declaration is done within the class definition

  4. Definition is given outside the class definition

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

This option is correct as the given statement is incorrect because however, static data member is visible within the class but its lifetime is the entire program.

Multiple choice
  1. It stores the elements in a sequence.

  2. This interface defines the methods by which you can group the elements in a collection of objects.

  3. It extends Map interface so that the keys are maintained in ascending order.

  4. It describes an element in the form of key-value pair in a map. This is an inner class of Map interface.

  5. This interface does not allow duplicate interface.

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

This statement is true about Map.Entry interface.

Multiple choice
  1. Constructors do not have return type.

  2. Constructor has the same name as that of the class.

  3. Constructors are called automatically upon object creation time.

  4. A constructor can be static.

  5. A constructor cannot be final.

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

No, a constructor cannot be a static. If it is static, then it is accessible within the class only but not by subclass as static variables are class variables.

Multiple choice
  1. Abstract class cannot be instantiated.

  2. Abstract class has both abstract and concrete methods.

  3. An abstract class has any public, private or protected members.

  4. A Java class can extend only one abstract class.

  5. A static method can be abstract in the abstract class.

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

No, a static method cannot be overridden by subclasses, so a static method cannot be abstract.

Multiple choice
  1. Virtual function is used to achieve dynamic binding in C++.

  2. We cannot instantiate the base class by defining pure virtual function in that class.

  3. We cannot create a virtual function without definition inside the base class.

  4. Both (2) and (3) are false.

  5. None of these

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

This is a false statement about virtual function in C++ as we can create a virtual function without defining the base class, which is known as pure virtual function.