Top 80+ Solved Object Oriented Programming (OOP) MCQ Questions Answer
Q. The main intention of using inheritance is ….........
a. to help in converting one data type to other
b. to hide the details of base class
c. to extend the capabilities of base class
d. to help in modular programming
Q. If particular software can be used in some other application than the one for which it is created then it reveals ….........
a. data binding
b. data reusability
c. data encapsulation
d. none of these
Q. How many objects can be created from an abstract class?
a. zero
b. one
c. two
d. as many as we want
Q. What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
a. compile-time error
b. preprocessing error
c. runtime error
d. runtime exception
Q. Which of the following interface determines how your program will be used by other program?
a. public
b. private
c. protected
d. none of these
Q. What is the difference between struct and class in C++?
a. all members of a structure are public and structures don't have constructors and destructors
b. members of a class are private by default and members of struct are public by default. when deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.
c. all members of a structure are public and structures don't have virtual functions
d. all above
Q. Predict the output of following C++ program#include<iostream> using namespace std;class Empty {}; int main(){cout <<sizeof(Empty); return 0;}
a. a non zero value
b. 0
c. compile time error
d. runtime error
Q. Which of the following is true about the following program#include <iostream> class Test{public:int i;void get();};void Test::get(){std::cout <<"Enter the value of i: "; std::cin >>i;}Test t; // Global object int main(){Test t; // local object t.get();std::cout <<"value of i in local t: "<<t.i<<'\n';::t.get();std::cout <<"value of i in global t: "<<::t.i<<'\n'; return 0;}
a. compiler error: cannot have two objects with same class name
b. compiler error in line "::t.get();"
Q. Which of the following is true about new when compared with malloc. 1) new is an operator, malloc is a function 2) new calls constructor, malloc doesn't 3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.
a. 1 and 3
b. 2 and 3
c. 1 and 2
d. all 1,2,3
Q. What happens when delete is used for a NULL pointer? int *ptr = NULL;delete ptr;
a. compile time error
b. run time error
Q. Which of the followings is/are automatically added to every class, if we do not write our own.
a. copy constructor
b. assignment operator
c. a constructor without any parameter
d. all