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. Private and protected data members of the class can be accessed by defining the friend function.

  2. Only protected data members of the class can be accessed by defining the friend function.

  3. Only private data members of the class can be accessed by defining the friend function.

  4. Only public and protected data members of the class can be accessed by defining the friend function.

  5. None of these

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

We can access private and protected members both in the class by making the friend function of that class.

Multiple choice
  1. A class is user-defined data type in C++, whereas a structure is not.

  2. A class has private access specifier by default, whereas a structure has protected access specifier in C++.

  3. A class has private access specifier by default, whereas a structure has public access specifier in C++.

  4. Both (1) and (3)

  5. Both (2) and (3)

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

This statement is true about class and the structure in C++ and this is the only difference between them.

Multiple choice
  1. We can use this variable in the member variable of the class.

  2. This keyword is used to modify the const objects of the mutable data members.

  3. This keyword is used to make the objects of data members as constant.

  4. Both (1) and (2)

  5. Both (1) and (3)

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

Both the options are true about mutable keyword in C++.

Multiple choice
  1. C++ is an object-oriented language.

  2. Encapsulation determines the binding of data variables and functions into a single unit.

  3. Data abstraction is a design approach with implementation in C++.

  4. Polymorphism can be achieved in C++ by virtual function.

  5. None of these

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

Abstraction determines only the interface not implementation. It can separate the interface with implementation.

Multiple choice
  1. We cannot create virtual constructor in C++.

  2. We cannot create virtual destructors in C++.

  3. We can define pure virtual destructor also in our program.

  4. Both (2) and (3)

  5. Both (1) and (2)

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

This is not a true statement. There is a necessary condition to make the destructor as virtual as our program can not manage the memory allocated by downward subclasses and it may be leaked.

Multiple choice
  1. There is no multiple inheritance in C++.

  2. C++ supports multilevel inheritance.

  3. Hybrid inheritance is possible in C++.

  4. Both (1) and (3)

  5. None of these

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

This is a false statement as C++ determines multilevel inheritance and in that case, a single derived class can inherit from two or more base classes.

Multiple choice
  1. There are two types of overloading, i.e. function overloading and operator overloading in C++.

  2. It is not necessary to initialise the static variables.

  3. We can have a static virtual function in C++.

  4. Both (2) and (3)

  5. None of these

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

Yes, both options are the false statements, so this option is correct according to the question.

Multiple choice
  1. A new color will be created.

  2. There will be a runtime exception.

  3. Parameters are not enough.

  4. There will be an error Compile time error : cannot find method color.

  5. Compile time error : Color is abstract, cannot create an object.

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

This is the correct answer because color constructor creates a new colour but it takes parameters in the range 0-255. But here the value passed is 284(in first parameter).So a runtime exception named “IllegalArgumentException” will be thrown by the JVM.So this is the correct answer.

Multiple choice
  1. 4

  2. 3

  3. 2

  4. 1

  5. None of these

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

This is correct choice because the constructor of the Font class takes Three parameters :-First :- first parameter is of String type which specifies the name of the Font.Second :- second parameter is of type int which specifies the style of the font like Font.BOLD.Third :- third parameter is of type int which specifies the size of the font.ExampleFont f1 = new Font(“Serif”, Font.BOLD, 32);So this option is true.

Multiple choice
  1. Multilevel, multiple and hierarchical inheritance’s instances are not involved.

  2. No such concept like virtual base class exists only functions can be made virtual.

  3. It creates only one instance of the super class.

  4. It helps in creating redundant data, when we want to achieve data security.

  5. Both 2 and 3

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

Virtual base class creates one instance of the super class.

Multiple choice
  1. Encapsulation means hiding of data from the inside view.

  2. Encapsulation can be achieved by proper use of modifiers.

  3. Abstraction is a process like generalization.

  4. Abstraction Is closely associated with encapsulation.

  5. All of the above are true statements.

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

Yes, this is the right option.

Multiple choice
  1. Overloading occurs in the same class.

  2. In method overriding, the return type of the method is different.

  3. Final methods can not be overridden.

  4. All of the above

  5. Only (1) and (3) are true statements.

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

Yes, both of these are true.