Object Oriented Programming MCQ (Multiple Choice Questions)
Object Oriented Programming MCQ (Multiple Choice Questions)
Answer: c
Explanation: Alan Kay invented OOP, Andrea Ferro was a part of SmallTalk Development. Dennis
invented C++ and Adele Goldberg was in team to develop SmallTalk but Alan actually had got
rewarded for OOP.
Answer: d
Explanation: Duplicate/Redundant data is dependent on programmer and hence can’t be guaranteed
by OOP. Code reusability is done using inheritance. Modularity is supported by using different code
files and classes. Codes are more efficient because of features of OOP.
3. Which was the first purely object oriented programming language developed?
a) Kotlin
b) SmallTalk
c) Java
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 1/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
d) C++
View Answer
Ads by
?Why this ad Stop seeing this ad
Answer: c
Explanation: OOP first came into picture in 1970’s by Alan and his team. Later it was used by some
programming languages and got implemented successfully, SmallTalk was first language to use pure
OOP and followed all rules strictly.
Answer: d
Explanation: Inheritance indicates the code reusability. Encapsulation and abstraction are meant to
hide/group data into one element. Polymorphism is to indicate different tasks performed by a single
entity.
advertisement
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 2/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
Answer: a
Explanation: We need not include any specific header file to use OOP concept in C++, only specific
functions used in code need their respective header files to be included or classes should be defined
if needed.
Answer: b
Explanation: As Java supports usual declaration of data variables, it is partial implementation of OOP.
Because according to rules of OOP, object constructors must be used, even for declaration of
variables.
c) Platform independent
d) Data binding
View Answer
Answer: c
Explanation: Platform independence is not feature of OOP. C++ supports OOP but it’s not a platform
independent language. Platform independence depends on the programming language.
Answer: b
Explanation: Firstly, keyword class should come, followed by the derived class name. Colon is must
followed by access in which base class has to be derived, followed by the base class name. And
finally the body of class. Semicolon after the body is also must.
d) Inheritance
View Answer
Answer: a
Explanation: Encapsulation is indicated by use of classes. Inheritance is shown by inheriting the
student class into topper class. Polymorphism is not shown here because we have defined the
constructor in the topper class but that doesn’t mean that default constructor is overloaded.
11. The feature by which one object can interact with another object is _____________
a) Message reading
b) Message Passing
c) Data transfer
d) Data Binding
View Answer
Answer: b
Explanation: The interaction between two object is called the message passing feature. Data transfer
is not a feature of OOP. Also, message reading is not a feature of OOP.
12. Which among the following, for a pure OOP language, is true?
a) The language should follow at least 1 feature of OOP
b) The language must follow only 3 features of OOP
c) The language must follow all the rules of OOP
d) The language should follow 3 or more features of OOP
View Answer
Answer: c
Explanation: The language must follow all the rules of OOP to be called a purely OOP language. Even
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 5/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
if a single OOP feature is not followed, then it’s known to be a partially OOP language.
advertisement
13. How many types of access specifiers are provided in OOP (C++)?
a) 4
b) 3
c) 2
d) 1
View Answer
Answer: b
Explanation: Only 3 types of access specifiers are available. Namely, private, protected and public. All
these three can be used according to the need of security of members.
14. In multilevel inheritance, which is the most significant feature of OOP used?
a) Code efficiency
b) Code readability
c) Flexibility
d) Code reusability
View Answer
Answer: d
Explanation: The classes using multilevel inheritance will use the code in all the subsequent
subclasses if available. Hence the most significant feature among the options given is code
reusability. This feature is generally intended to use the data values and reuse the redundant
functions.
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 6/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
Answer: a
Explanation: It is a way of combining both data members and member functions, which operate on
those data members, into a single unit. We call it a class in OOP generally. This feature have helped
us modify the structures used in C language to be upgraded into class in C++ and other languages.
Answer: b
Explanation: It never increases function definition overhead, one way or another if you don’t use
polymorphism, you will use the definition in some other way, so it actually helps to write efficient
codes.
17. Which constructor will be called from the object created in the below C++ code?
advertisement
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 7/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
class A
{
int i;
A()
{
i=0; cout<<i;
}
A(int x=0)
{
i=x; cout<<I;
}
};
A obj1;
a) Parameterized constructor
b) Default constructor
c) Run time error
d) Compile time error
View Answer
Answer: d
Explanation: When a default constructor is defined and another constructor with 1 default value
argument is defined, creating object without parameter will create ambiguity for the compiler. The
compiler won’t be able to decide which constructor should be called, hence compile time error.
Answer: a
Explanation: It includes hiding the implementation part and showing only the required data and
features to the user. It is done to hide the implementation complexity and details from the user. And
to provide a good interface in programming.
Answer: b
Explanation: Only insertion operator can be overloaded among all the given options. And the
polymorphism can be illustrated here only if any of these is applicable of being overloaded.
Overloading is type of polymorphism.
20. In which access should a constructor be defined, so that object of the class can be created in any
function?
a) Any access specifier will work
b) Private
c) Public
d) Protected
View Answer
Answer: c
Explanation: Constructor function should be available to all the parts of program where the object is
to be created. Hence it is advised to define it in public access, so that any other function is able to
create objects.
21. Which among the following is correct for the class defined below?
class student
{
int marks;
public: student(){}
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 9/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
student(int x)
{
marks=x;
}
};
main()
{
student s1(100);
student s2();
student s3=100;
return 0;
}
Answer: c
Explanation: When an object is passed to a function, actually its copy is made in the function. To copy
the values, copy constructor is used. Hence the object being passed and object being used in
function are different.
23. Which constructor will be called from the object obj2 in the following C++ program?
class A
{
int i;
A()
{
i=0;
}
A(int x)
{
i=x+1;
}
A(int y, int x)
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 10/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
{
i=x+y;
}
};
A obj1(10);
A obj2(10,20);
A obj3;
a) A(int y, int x)
b) A(int y; int x)
c) A(int y)
d) A(int x)
View Answer
Answer: b
Explanation: The constructors must contain only the class name. The class name is followed by the
blank parenthesis or we can have parameters if some values are to be passed.
Answer: c
Explanation: The destructor is never called in this situation. The concept is that when an object is
passed by reference to the function, the constructor is not called, but only the main object will be
used. Hence no destructor will be called at end of function.
26. Which access specifier is usually used for data members of a class?
a) Protected
b) Private
c) Public
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 11/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
d) Default
View Answer
Answer: b
Explanation: All the data members should be made private to ensure the highest security of data. In
special cases we can use public or protected access, but it is advised to keep the data members
private always.
Answer: d
Explanation: The data members can never be called directly. Dot operator is used to access the
members with help of object of class. Arrow is usually used if pointers are used.
Answer: a
Explanation: Using inheritance we can have the security of the class being inherited. The subclass
can access the members of parent class. And have more feature than a nested class being used.
29. Which keyword among the following can be used to declare an array of objects in java?
a) allocate
b) arr
c) new
d) create
View Answer
Answer: c
Explanation: The keyword new can be used to declare an array of objects in java. The syntax must be
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 12/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
specified with an object pointer which is assigned with a memory space containing the required
number of object space. Even initialization can be done directly.
30. Which operator can be used to free the memory allocated for an object in C++?
a) Unallocate
b) Free()
c) Collect
d) delete
View Answer
Answer: d
Explanation: The delete operator in C++ can be used to free the memory and resources held by an
object. The function can be called explicitly whenever required. In C++ memory management must
be done by the programmer. There is no automatic memory management in C++.
Answer: b
Explanation: The names are not property of an object. The identity can be in any form like address or
name of object but name can’t be termed as only identity of an object. The objects contain attributes
that define what type of data an object can store.
32. Which type of members can’t be accessed in derived classes of a base class?
a) All can be accessed
b) Protected
c) Private
d) Public
View Answer
Answer: c
Explanation: The private members can be accessed only inside the base class. If the class is derived
by other classes. Those members will not be accessible. This concept of OOP is made to make the
members more secure.
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 13/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
Answer: a
Explanation: It can only be indicated by using the data and functions that we use in derived class,
being provided by parent class. Copying code is nowhere similar to this concept, also using the code
already written is same as copying. Using already defined functions is not inheritance as we are not
adding any of our own features.
Answer: d
Explanation: The runtime inheritance is done when object of a class is created to call a method. At
runtime the function is searched if it is in class of object. If not, it will search in its parent classes and
hierarchy for that method.
Answer: b
Explanation: To overcome the ambiguity and conflict we can use keyword virtual. This will help us to
differentiate the functions with same name that came to last derived class in diamond problem.
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 14/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
d) anonymous
View Answer
Answer: c
Explanation: The virtual keyword is used to declare virtual functions. Anonymous keyword is used
with classes and have a different meaning. The virtual functions are used to call the intended
function of the derived class.
37. What happens if non static members are used in static member function?
a) Executes fine
b) Compile time error
c) Executes if that member function is not used
d) Runtime error
View Answer
Answer: b
Explanation: There must be specific memory space allocated for the data members before the static
member functions uses them. But the space is not reserved if object is not declared. Hence only if
static members are not used, it leads to compile time error.
Answer: a
Explanation: A non-member function of a class which can access even the private data of a class is a
friend function. It is an exception on access to private members outside the class. It is sometimes
considered as a member functions since it has all the access that a member function in general have.
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 15/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
Answer: d
Explanation: The memory for the objects or any other data is allocated in RAM initially. This is while
we run a program all the memory allocation takes place in some RAM segments. Arrays in heap and
local members in stack etc.
Answer: c
Explanation: The member function which is defined in base class and again in the derived class, is
overridden by the definition given in the derived class. This is because the preference is given more
to the local members. When derived class object calls that function, definition from the derived class
is used.
Answer: b
Explanation: Abstraction is hiding the complex code. For example, we directly use cout object in C++
but we don’t know how is it actually implemented. Encapsulation is data binding, as in, we try to
combine a similar type of data and functions together.
Answer: a
Explanation: The polymorphism feature is exhibited by function overriding. Polymorphism is the
feature which basically defines that same named functions can have more than one functionalities.
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 16/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
Answer: d
Explanation: Even the private member functions can be called outside the class. This is possible if
address of the function is known. We can use the address to call the function outside the class.
Answer: c
Explanation: The keyword used to declare static variables is static. This is must be used while
declaring the static variables. The compiler can make variables static if and only if they are
mentioned with static keyword.
Answer: b
Explanation: The syntax must contain * symbol after the className as the type of object. This
declares an object pointer. This can store address of any object of the specified class.
46. Which class/set of classes can illustrate polymorphism in the following C++ code?
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 17/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
}
class topper:public student
{
public : calc_grade()
{
return 10;
}
};
class average:public student
{
public : calc_grade()
{
return 20;
}
};
class failed{ int marks; };
Answer: d
Explanation: Since Student class is abstract class and class topper and average are inheriting student,
class topper and average must define the function named calc_grade(); in abstract class. Since both
the definition are different in those classes, calc_grade() will work in different way for same input
from different objects. Hence it shows polymorphism.
47. If data members are private, what can we do to access them from the class object?
a) Private data members can never be accessed from outside the class
b) Create public member functions to access those data members
c) Create private member functions to access those data members
d) Create protected member functions to access those data members
View Answer
Answer: b
Explanation: We can define public member functions to access those private data members and get
their value for use or alteration. They can’t be accessed directly but is possible to be access using
member functions. This is done to ensure that the private data doesn’t get modified accidentally.
48. Which among the following is not a necessary condition for constructors?
a) Its name must be same as that of class
b) It must not have any return type
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 18/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
Answer: c
Explanation: Constructors are predefined implicitly, even if the programmer doesn’t define any of
them. Even if the programmer declares a constructor, it’s not necessary that it must contain some
definition.
Answer: d
Explanation: This is mandatory to pass the object by reference. Otherwise, the object will try to
create another object to copy its values, in turn a constructor will be called, and this will keep on
calling itself. This will cause the compiler to give out of memory error.
50. If in multiple inheritance, class C inherits class B, and Class B inherits class A. In which sequence are
their destructors called if an object of class C was declared?
a) ~A() then ~B() then ~C()
b) ~C() then ~A() then ~B()
c) ~C() then ~B() then ~A()
d) ~B() then ~C() then ~A()
View Answer
Answer: c
Explanation: The destructors are always called in the reverse order of how the constructors were
called. Here class A constructor would have been created first if Class C object is declared. Hence
class A destructor is called at last.
Answer: b
Explanation: Instance of abstract class can’t be created as it will not have any constructor of its own,
hence while creating an instance of class, it can’t initialize the object members. Actually the class
inheriting the abstract class can have its instance because it will have implementation of all
members.
Answer: a
Explanation: Virtual Functions can be defined in any class using the keyword virtual. All the classes
which inherit the class containing the virtual function, define the virtual function as required.
Redefining the function on all the derived classes according to class and use represents
polymorphism.
53. Which feature in OOP is used to allocate additional functions to a predefined operator in any
language?
a) Function Overloading
b) Function Overriding
c) Operator Overloading
d) Operator Overriding
View Answer
Answer: c
Explanation: The feature is operator overloading. There is not a feature named operator overriding
specifically. Function overloading and overriding doesn’t give addition function to any operator.
Answer: d
Explanation: Data abstraction can be achieved by using encapsulation. We can hide the operation
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 20/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
and structure of actual program from the user and can show only required information by the user.
Object Oriented Programming MCQ: Data Object Oriented Programming MCQ: Local
Members Class
Object Oriented Programming MCQ: Member Object Oriented Programming MCQ: Nested
Functions Class
The section contains questions and answers on passing and returning object with functions, object
reference and memory allocation, object array and usage.
OOPs MCQ: Passing and Returning Object OOPs MCQ: Object Array
with Functions
OOPs MCQ: Object Use
OOPs MCQ: Object Reference
OOPs MCQ: Memory Allocation of Object
Object Oriented Programming MCQ: Abstract Object Oriented Programming MCQ: Derived
Class Class
Object Oriented Programming MCQ: Object Oriented Programming MCQ: Class
Template Class Use
Object Oriented Programming MCQ: Base
Class
programming.
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 24/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 25/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
If you would like to learn "Object Oriented Programming" thoroughly, you should attempt to work on
the complete set of 1000+ MCQs - multiple choice questions and answers mentioned above. It will
immensely help anyone trying to crack an exam or an interview.
Wish you the best in your endeavor to learn and master Object Oriented Programming!
advertisement
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 26/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
Additional Resources:
R Programming MCQ Questions
C++ Programming MCQ Questions
Java Programming MCQ Questions
Ruby MCQ Questions
Programming MCQ Questions
Popular Pages:
C Programming MCQ Questions
Visual Basic MCQ Questions
C# MCQ Questions
LISP MCQ Questions
JavaScript MCQ Questions
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at
Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies,
Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 27/28
6/22/24, 6:44 PM OOPs MCQ (Multiple Choice Questions) - Sanfoundry
https://www.sanfoundry.com/1000-object-oriented-programming-oops-questions-answers/ 28/28