Sei sulla pagina 1di 109

Object Oriented Programming Questions and Answers – OOPs

Basic Concepts
This set of Object Oriented Programming online test focuses on “OOP Basic Concepts”.
1. Which was the first purely object oriented programming language developed?
a) Java
b) C++
c) SmallTalk
d) Kotlin
View Answer
Answer: c
Explanation: SmallTalk was the first programming language developed which was purely object
oriented. It was developed by Alan Kay. OOP concept came into picture in 1970’s.
2. Which of the following best defines a class?
a) Parent of an object
b) Instance of an object
c) Blueprint of an object
d) Scope of an object
View Answer
Answer: b
Explanation: A class is Blueprint of an object which describes/ shows all the functions and data that
are provided by an object of a specific class. It can’t be called as parent or instance of an object.
Class in general describes all the properties of an object.
3. Who invented OOP?
a) Alan Kay
b) Andrea Ferro
c) Dennis Ritchie
d) Adele Goldberg
View Answer
Answer: a
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.
4. What is the additional feature in classes that was not in structures?
a) Data members
b) Member functions
c) Static data allowed
d) Public access specifier
View Answer
Answer: b
Explanation: Member functions are allowed inside a class but were not present in structure concept.
Data members, static data and public access specifiers were present in structures too.
5. Which is not feature of OOP in general definitions?
a) Code reusability
b) Modularity
c) Duplicate/Redundant data
d) Efficient Code
View Answer
Answer: c
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.
6. Pure OOP can be implemented without using class in a program. (True or False)
a) True
b) False
View Answer
Answer: b
Explanation: It’s false because for a program to be pure OO, everything must be written inside
classes. If this rule is violated, the program can’t be labelled as purely OO.
7. Which Feature of OOP illustrated the code reusability?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Inheritance
View Answer
Answer: d
Explanation: Using inheritance we can reuse the code already written and also can avoid creation of
many new functions or variables, as that can be done one time and be reused, using classes.
8. Which language does not support all 4 types of inheritance?
a) C++
b) Java
c) Kotlin
d) Small Talk
View Answer
Answer: b
Explanation: Java doesn’t support all 4 types of inheritance. It doesn’t support multiple inheritance.
But the multiple inheritance can be implemented using interfaces in Java.
9. How many classes can be defined in a single program?
a) Only 1
b) Only 100
c) Only 999
d) As many as you want
View Answer
Answer: d
Explanation: Any number of classes can be defined inside a program, provided that their names are
different. In java, if public class is present then it must have the same name as that of file.
10. When OOP concept did first came into picture?
a) 1970’s
b) 1980’s
c) 1993
d) 1995
View Answer
Answer: a
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.
11. Why Java is Partially OOP language?
a) It supports usual declaration of primitive data types
b) It doesn’t support all types of inheritance
c) It allows code to be written outside classes
d) It does not support pointers
View Answer
Answer: a
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.
12. Which concept of OOP is false for C++?
a) Code can be written without using classes
b) Code must contain at least one class
c) A class must have member functions
d) At least one object should be declared in code
View Answer
Answer: b
Explanation: In C++, it’s not necessary to use classes, and hence codes can be written without using
OOP concept. Classes may or may not contain member functions, so it’s not a necessary condition
in C++. And, an object can only be declared in a code if its class is defined/included via header file.
13. Which header file is required in C++ to use OOP?
a) iostream.h
b) stdio.h
c) stdlib.h
d) OOP can be used without using any header file
View Answer
Answer: d
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.
14. Which of the two features match each other?
a) Inheritance and Encapsulation
b) Encapsulation and Polymorphism
c) Encapsulation and Abstraction
d) Abstraction and Polymorphism
View Answer
Answer: c
Explanation: Encapsulation and Abstraction are similar features. Encapsulation is actually binding all
the properties in a single class or we can say hiding all the features of object inside a class. And
Abstraction is hiding unwanted data (for user) and showing only the data required by the user of
program.
15. Which feature allows open recursion, among the following?
a) Use of this pointer
b) Use of pointers
c) Use of pass by value
d) Use of parameterized constructor
View Answer
Answer: a
Explanation: Use of this pointer allows an object to call data and methods of itself whenever needed.
This helps us call the members of an object recursively, and differentiate the variables of different
scopes.

Object Oriented Programming Questions and Answers –


Classes
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers
(MCQs) focuses on “Classes”.
1. Which of the following is not type of class?
a) Abstract Class
b) Final Class
c) Start Class
d) String Class
View Answer
Answer: c
Explanation: Only 9 types of classes are provided in general, namely, abstract, final, mutable,
wrapper, anonymous, input-output, string, system, network. We may further divide the classes into
parent class and sub class if inheritance is used.
2. Class is pass by _______
a) Value
b) Reference
c) Value or Reference, depending on program
d) Copy
View Answer
Answer: b
Explanation: Classes are pass by reference, and the structures are pass by copy. It doesn’t depend
on program.
3. What is default access specifier for data members or member functions declared within a
class without any specifier, in C++ ?
a) Private
b) Protected
c) Public
d) Depends on compiler
View Answer
Answer: a
Explanation: The data members and member functions are Private by default in C++ classes, if none
of the access specifier is used. It is actually made to increase the privacy of data.
4. Which is most appropriate comment on following class definition :
class Student
{
int a;
public : float a;
};
a) Error : same variable name can’t be used twice
b) Error : Public must come first
c) Error : data types are different for same variable
d) It is correct
View Answer
Answer: a
Explanation: Same variable can’t be defined twice in same scope. Even if the data types are
different, variable name must be different. There is no rule like Public member should come first or
last.
5. Which is known as generic class?
a) Abstract class
b) Final class
c) Template class
d) Efficient Code
View Answer
Answer: c
Explanation: Template classes are known to be generic classes because those can be used for any
data type value and the same class can be used for all the variables of different data types.
6. Size of a class is :
a) Sum of size of all the variables declared inside the class
b) Sum of size of all the variables along with inherited variables in the class
c) Size of largest size of variable
d) Classes doesn’t have any size
View Answer
Answer: d
Explanation: Classes doesn’t have any size, actually the size of object of the class can be defined.
That is done only when an object is created and its constructor is called.
7. Which class can have member functions without their implementation?
a) Default class
b) String class
c) Template class
d) Abstract class
View Answer
Answer: d
Explanation: Abstract classes can have member functions with no implementation, where the
inheriting sub classes must implement those functions.
8. Which of the following describes a friend class?
a) Friend class can access all the private members of the class, of which it is a friend
b) Friend class can only access protected members of the class, of which it is a friend
c) Friend class don’t have any implementation
d) Friend class can’t access any data member of another class but can use it’s methods
View Answer
Answer: a
Explanation: A friend class can access all the private members of another class, of which it is friend.
It is a special class provided to use when you need to reuse the data of a class but don’t want that
class to have those special functions.
9. What is scope of a class nested inside another class?
a) Protected scope
b) Private scope
c) Global scope
d) Depends on access specifier and inheritance used
View Answer
Answer: d
Explanation: It depends on the access specifier and the type of inheritance used with the class,
because if the class is inherited then the nested class can be used by subclass too, provided it’s not
of private type.
10. Class with main() function can be inherited (True/False)
a) True
b) False
View Answer
Answer: a
Explanation: The class containing main function can be inherited and hence the program can be
executed using the derived class names also in java.
11. Which among the following is false, for member function of a class?
a) All member functions must be defined
b) Member functions can be defined inside or outside the class body
c) Member functions need not be declared inside the class definition
d) Member functions can be made friend to another class using friend keyword
View Answer
Answer: c
Explanation: Member functions must be declared inside class body, thought the definition can be
given outside the class body. There is no way to declare the member functions inside the class.
12. Which syntax for class definition is wrong?
a) class student{ };
b) student class{ };
c) class student{ public: student(int a){ } };
d) class student{ student(int a){} };
View Answer
Answer: b
Explanation: Keyword class should come first. Class name should come after keyword class.
Parameterized constructor definition depends on programmer so it can be left empty also.
13. Which of the following pairs are similar?
a) Class and object
b) Class and structure
c) Structure and object
d) Structure and functions
View Answer
Answer: b
Explanation: Class and structure are similar to each other. Only major difference is that a structure
doesn’t have member functions whereas the class can have both data members and member
functions.
14. Which among the following is false for class features?
a) Classes may/may not have both data members and member functions
b) Class definition must be ended with a colon
c) Class can have only member functions with no data members
d) Class is similar to union and structures
View Answer
Answer: b
Explanation: Class definition must end with a semicolon, not colon. Class can have only member
functions in its body with no data members.
15. Instance of which type of class can’t be created?
a) Anonymous class
b) Nested class
c) Parent class
d) Abstract class
View Answer
Answer: d
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.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Objects”.
1. Which definition best describes an object?
a) Instance of a class
b) Instance of itself
c) Child of a class
d) Overview of a class
View Answer
Answer: a
Explanation: An object is instance of its class. It can be declared in the same way that a variable is
declared, only thing is you have to use class name as the data type.
2. How many objects can be declared of a specific class in a single program?
a) 32768
b) 127
c) 1
d) As many as you want
View Answer
Answer: d
Explanation: You can create as many objects of a specific class as you want, provided enough
memory is available.
3. Which among the following is false?
a) Object must be created before using members of a class
b) Memory for an object is allocated only after its constructor is called
c) Objects can’t be passed by reference
d) Objects size depends on its class data members
View Answer
Answer: c
Explanation: Objects can be passed by reference. Objects can be passed by value also. If object of
a class is not created, we can’t use members of that class.
4. Which of the following is incorrect?
a) class student{ }s;
b) class student{ }; student s;
c) class student{ }s[];
d) class student{ }; student s[5];
View Answer
Answer: c
Explanation: The array must be specified with a size. You can’t declare object array, or any other
linear array without specifying its size. It’s a mandatory field.
5. The object can’t be:
a) Passed by reference
b) Passed by value
c) Passed by copy
d) Passed as function
View Answer
Answer: d
Explanation: Object can’t be passed as function as it is an instance of some class, it’s not a function.
Object can be passed by reference, value or copy. There is no term defined as pass as function for
objects.
6. What is size of the object of following class (64 bit system)?
class student { int rollno; char name[20]; static int studentno; };
a) 20
b) 22
c) 24
d) 28
View Answer
Answer: c
Explanation: The size of any object of student class will be of size 4+20=24, because static
members are not really considered as property of a single object. So static variables size will not be
added.
7. Functions can’t return objects. (True/False)
a) True
b) False
View Answer
Answer: b
Explanation: Functions can always return an object if the return type is same as that of object being
returned. Care has to be taken while writing the prototype of function.
8. How members of an object are accessed?
a) Using dot operator/period symbol
b) Using scope resolution operator
c) Using member names directly
d) Using pointer only
View Answer
Answer: a
Explanation: Using dot operator after the name of object we can access its members. It is not
necessary to use the pointers. We can’t use the names directly because it may be used outside the
class.
9. If a local class is defined in a function, which of the following is true for an object of that class?
a) Object is accessible outside the function
b) Object can be declared inside any other function
c) Object can be used to call other class members
d) Object can be used/accessed/declared locally in that function.
View Answer
Answer: d
Explanation: For an object which belongs to a local class, it is mandatory to declare and use the
object within the function because the class is accessible locally within the class only.
10. Which among the following is wrong?
a) class student{ }; student s;
b) abstract class student{ }; student s;
c) abstract class student{ }s[50000000];
d) abstract class student{ }; class toppers: public student{ }; topper t;
View Answer
Answer: b
Explanation: We can never create instance of an abstract class. Abstract classes doesn’t have
constructors and hence when an instance is created there is no facility to initialize its members.
Option d is correct because topper class is inheriting the base abstract class student, and hence
topper class object can be created easily.
11. Object declared in main() function:
a) Can be used by any other function
b) Can be used by main() function of any other program
c) Can’t be used by any other function
d) Can be accessed using scope resolution operator
View Answer
Answer: c
Explanation: The object declared in main() have local scope inside main() function only. It can’t be
used outside main() function. Scope resolution operator is used to access globally declared
variables/objects.
12. When an object is returned___________
a) A temporary object is created to return the value
b) The same object used in function is used to return the value
c) The Object can be returned without creation of temporary object
d) Object are returned implicitly, we can’t say how it happens inside program
View Answer
Answer: a
Explanation: A temporary object is created to return the value. It is created because object used in
function is destroyed as soon as the function is returned. The temporary variable returns the value
and then gets destroyed.
13. Which among the following is correct?
a) class student{ }s1,s2; s1.student()=s2.student();
b) class student{ }s1; class topper{ }t1; s1=t1;
c) class student{ }s1,s2; s1=s2;
d) class student{ }s1; class topper{ }t1; s1.student()=s2.topper();
View Answer
Answer: c
Explanation: Only if the objects are of same class then their data can be copied from to another
using assignment operator. This actually comes under operator overloading. Class constructors
can’t be assigned any explicit value as in option b and d.
14. Which among following is correct for initializing the class below?
class student{
int marks;
int cgpa;
public: student(int i, int j){
marks=I;
cgpa=j
}
};
a) student s[3]={ s(394, 9); s(394, 9); s(394,9); };
b) student s[2]={ s(394,9), s(222,5) };
c) student s[2]={ s1(392,9), s2(222,5) };
d) student s[2]={ s[392,9], s2[222,5] };
View Answer
Answer: b
Explanation: It is the way we can initialize the data members for an object array using parameterized
constructor. We can do this to pass our own intended values to initialize the object array data.
15. Object can’t be used with pointers because they belong to user defined class, and compiler can’t
decide the type of data may be used inside the class. (True/False)
a) True
b) False
View Answer
Answer: b
Explanation: The explanation given is wrong because object can always be used with pointers like
with any other variables. Compiler doesn’t have to know the structure of the class to use a pointer
because the pointers only points to a memory address/stores that address.

his set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “OOP Features”.
1. Which feature of OOP indicates code reusability?
a) Encapsulation
b) Inheritance
c) Abstraction
d) Polymorphism
View Answer
Answer: b
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.
2. If a function can perform more than 1 type of tasks, where the function name remains same,
which feature of OOP is used here?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction
View Answer
Answer: c
Explanation: For the feature given above, the OOP feature used is Polymorphism. Example of
polymorphism in real life is a kid, who can be a student, a son, a brother depending on where he is.
3. If different properties and functions of a real world entity is grouped or embedded into a single
element, what is it called in OOP language?
a) Inheritance
b) Polymorphism
c) Abstraction
d) Encapsulation
View Answer
Answer: d
Explanation: It is Encapsulation, which groups different properties and functions of a real world entity
into single element. Abstraction, on other hand, is hiding of functional or exact working of codes and
showing only the things which are required by the user.
4. Which of the following is not feature of pure OOP?
a) Classes must be used
b) Inheritance
c) Data may/may not be declared using object
d) Functions Overloading
View Answer
Answer: c
Explanation: Data must be declared using objects. Object usage is mandatory because it in turn
calls its constructors, which in turn must have a class defined. If object is not used, it is violation of
pure OOP concept.
5. Which among the following doesn’t come under OOP concept?
a) Platform independent
b) Data binding
c) Message passing
d) Data hiding
View Answer
Answer: a
Explanation: Platform independence is not feature of OOP. C++ supports OOP but it’s not a platform
independent language. Platform independence depends on programming language.
6. Which feature of OOP is indicated by the following code?
class student{ int marks; };
class topper:public student{ int age; topper(int age){ this.age=age; } };
a) Inheritance
b) Polymorphism
c) Inheritance and polymorphism
d) Encapsulation and Inheritance
View Answer
Answer: d
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 topper class but that doesn’t mean that default constructor is overloaded.
7. Which feature may be violated if we don’t use classes in a program?
a) Inheritance can’t be implemented
b) Object must be used is violated
c) Encapsulation only is violated
d) Basically all the features of OOP gets violated
View Answer
Answer: d
Explanation: All the features are violated because Inheritance and Encapsulation won’t be
implemented. Polymorphism and Abstraction is still possible in some cases, but the main features
like data binding, object use and etc won’t be used hence use of class is must for OOP concept.
8. How many basic features of OOP are required for a programming language to be purely OOP?
a) 7
b) 6
c) 5
d) 4
View Answer
Answer: a
Explanation: There are 7 basic features that define whether a programing language is pure OOP or
not. The 4 basic features are inheritance, polymorphism, encapsulation and abstraction. Further, one
is, object use is must, secondly, message passing and lastly, Dynamic binding.
9. The feature by which one object can interact with another object is:
a) Data transfer
b) Data Binding
c) Message Passing
d) Message reading
View Answer
Answer: c
Explanation: The interaction between two object is called message passing feature. Data transfer is
not feature of OOP. Also, message reading is not feature of OOP.
10. ___________ underlines the feature of Polymorphism in a class.
a) Nested class
b) Enclosing class
c) Inline function
d) Virtual Function
View Answer
Answer: d
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.
11. Which feature in OOP is used to allocate additional function to a predefined operator in any
language?
a) Operator Overloading
b) Function Overloading
c) Operator Overriding
d) Function Overriding
View Answer
Answer: a
Explanation: The feature is operator overloading. There is not feature named operator overriding
specifically. Function overloading and overriding doesn’t give addition function to any operator.
12. Which among doesn’t illustrates polymorphism?
a) Function overloading
b) Function overriding
c) Operator overloading
d) Virtual function
View Answer
Answer: b
Explanation: Function overriding doesn’t illustrate polymorphism because the functions are actually
different and theirs scopes are different. Function and operator overloading illustrate proper
polymorphism. Virtual functions show polymorphism because all the classes which inherit virtual
function, define the same function in different ways.
13. Exception handling is feature of OOP. (True/False)
a) True
b) False
View Answer
Answer: a
Explanation: Exception handling is feature of OOP as it includes classes concept in most of the
cases. Also it may come handy while using inheritance.
14. Which among the following, for a pure OOP language, is true?
a) The language should follow 3 or more features of OOP
b) The language should follow at least 1 feature of OOP
c) The language must follow only 3 features of OOP
d) The language must follow all the rules of OOP
View Answer
Answer: d
Explanation: The language must follow all the rules of OOP to be called a purely OOP language.
Even if a single OOP feature is not followed, then it’s known to be a partially OOP language.
15. OOP provides better security than POP:
a) Always true for any programming language
b) May not be true with respect to all programming languages
c) It depends on type of program
d) It’s vice-versa is true
View Answer
Answer: a
Explanation: It is always true as we have the facility of private and protected access specifiers. Also,
only the public and global data is available globally or else program should have proper permission
to access the private data.
is set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Polymorphism”.
1. Which among the following best describes polymorphism?
a) It is the ability for a message/data to be processed in more than one form
b) It is the ability for a message/data to be processed in only 1 form
c) It is the ability for many messages/data to be processed in one way
d) It is the ability for undefined message/data to be processed in at least one way
View Answer
Answer: a
Explanation: It is actually the ability for a message / data to be processed in more than one form.
The word polymorphism indicates many-forms. So if a single entity takes more than one form, it is
known as polymorphism.
2. What do you call the languages that support classes but not polymorphism?
a) Class based language
b) Procedure Oriented language
c) Object-based language
d) If classes are supported, polymorphism will always be supported
View Answer
Answer: c
Explanation: The languages which support classes but doesn’t support polymorphism, are known as
object-based languages. Polymorphism is such an important feature, that is a language doesn’t
support this feature, it can’t be called as a OOP language.
3. Which among the following is the language which supports classes but not polymorphism?
a) SmallTalk
b) Java
c) C++
d) Ada
View Answer
Answer: d
Explanation: Ada is the language which supports the concept of classes but doesn’t support the
polymorphism feature. It is an object-based programming language. Note that it’s not an OOP
language.
4. If same message is passed to objects of several different classes and all of those can respond in
a different way, what is this feature called?
a) Inheritance
b) Overloading
c) Polymorphism
d) Overriding
View Answer
Answer: c
Explanation: The feature defined in question defines polymorphism feature. Here the different
objects are capable of responding to the same message in different ways, hence polymorphism.
5. Which class/set of classes can illustrate polymorphism in the following code:
abstract class student
{
public : int marks;
calc_grade();
}
class topper:public student
{
public : calc_grade()
{
return 10;
}
};
class average:public student
{
public : calc_grade()
{
return 20;
}
};
class failed{ int marks; };
a) Only class student can show polymorphism
b) Only class student and topper together can show polymorphism
c) All class student, topper and average together can show polymorphism
d) Class failed should also inherit class student for this code to work for polymorphism
View Answer
Answer: c
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.
6. Which type of function among the following shows polymorphism?
a) Inline function
b) Virtual function
c) Undefined functions
d) Class member functions
View Answer
Answer: b
Explanation: Only virtual functions among these can show polymorphism. Class member functions
can show polymorphism too but we should be sure that the same function is being overloaded or is a
function of abstract class or something like this, since we are not sure about all these, we can’t say
whether it can show polymorphism or not.
7. In case of using abstract class or function overloading, which function is supposed to be called
first?
A) Local function
B) Function with highest priority in compiler
C) Global function
D) Function with lowest priority because it might have been halted since long time, because of low
priority
View Answer
Answer: b
Explanation: Function with highest priority is called. Here, it’s not about the thread scheduling in
CPU, but it focuses on whether the function in local scope is present or not, or if scope resolution is
used in some way, or if the function matches the argument signature. So all these things define
which function has the highest priority to be called in runtime. Local function could be one of the
answer but we can’t say if someone have used pointer to another function or same function name.
8. Which among the following can’t be used for polymorphism?
a) Static member functions
b) Member functions overloading
c) Predefined operator overloading
d) Constructor overloading
View Answer
Answer: a
Explanation: Static member functions are not property of any object. Hence it can’t be considered for
overloading/overriding. For polymorphism, function must be property of object, not only of class.
9. What is output of the following program?
class student
{
public : int marks;
void disp()
{
cout<<”its base class”
};
class topper:public student
{
public :
void disp()
{
cout<<”Its derived class”;
}
}
void main() { student s; topper t;
s.disp();
t.disp();
}
a) Its base classIts derived class
b) Its base class Its derived class
c) Its derived classIts base class
d) Its derived class Its base class
View Answer
Answer: a
Explanation: You need to focus on how the output is going to be shown, no space will be given after
first message from base class. And then the message from derived class will be printed. Function
disp() in base class overrides the function of base class being derived.
10. Which among the following can show polymorphism?
a) Overloading ||
b) Overloading +=
c) Overloading <<
d) Overloading &&
View Answer
Answer: c
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.
11. Find the output of the program:
class education
{
char name[10];
public : disp()
{
cout<<”Its education system”;
}
class school:public education
{
public: void dsip()
{
cout<<”Its school education system”;
}
};
void main()
{
school s;
s.disp();
}
}
a) Its school education system
b) Its education system
c) Its school education systemIts education system
d) Its education systemIts school education system
View Answer
Answer: a
Explanation: Notice that the function name in derived class is different from the function name in
base class. Hence when we call the disp() function, base class function is executed. No
polymorphism is used here.
12. Polymorphism is possible in C language.
a) True
b) False
View Answer
Answer: a
Explanation: It is possible to implement polymorphism in C language, even though it doesn’t support
class. We can use structures and then declare pointers which in turn points to some function. In this
way we simulate the functions like member functions but not exactly member function. Now we can
overload these functions, hence implementing polymorphism in C language.
13. Which problem may arise if we use abstract class functions for polymorphism?
a) All classes are converted as abstract class
b) Derived class must be of abstract type
c) All the derived classes must implement the undefined functions
d) Derived classes can’t redefine the function
View Answer
Answer: c
Explanation: The undefined functions must be defined is a problem, because one may need to
implement few undefined functions from abstract class, but he will have to define each of the
functions declared in abstract class. Being useless task, it is a problem sometimes.
14. Which among the following is not true for polymorphism?
a) It is feature of OOP
b) Ease in readability of program
c) Helps in redefining the same functionality
d) Increases overhead of function definition always
View Answer
Answer: d
Explanation: It never increases function definition overhead, one way or other if you don’t use
polymorphism, you will use the definition in some other way, so it actually helps to write efficient
codes.
15. If 2 classes derive one base class and redefine a function of base class, also overload some
operators inside class body. Among these two things of function and operator overloading, where is
polymorphism used?
a) Function overloading only
b) Operator overloading only
c) Both of these are using polymorphism
d) Either function over loading or operator overloading because polymorphism can be applied only
once in a program
View Answer
Answer: d
Explanation: Both of them are using polymorphism. It is not a necessary that polymorphism can be
used only once in a program, it can be used anywhere, any number of times in a single program.

his set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Encapsulation”.
1. Which among the following best describes encapsulation?
a) It is a way of combining various data members into a single unit
b) It is a way of combining various member functions into a single unit
c) It is a way of combining various data members and member functions into a single unit which can
operate on any data
d) It is a way of combining various data members and member functions that operate on those data
members into a single unit
View Answer
Answer: d
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.
2. If data members are private, what can we do to access them from the class object?
a) Create public member functions to access those data members
b) Create private member functions to access those data members
c) Create protected member functions to access those data members
d) Private data members can never be accessed from outside the class
View Answer
Answer: a
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 accidently.
3. While using encapsulation, which among the following is possible?
a) Code modification can be additional overhead
b) Data member’s data type can be changed without changing any other code
c) Data member’s type can’t be changed, or whole code have to be changed
d) Member functions can be used to change the data type of data members
View Answer
Answer: b
Explanation: Data member’s data type can be changed without changing any further code. All the
members using that data can continue in the same way without any modification. Member functions
can never change the data type of same class data members.
4. Which feature can be implemented using encapsulation?
a) Inheritance
b) Abstraction
c) Polymorphism
d) Overloading
View Answer
Answer: b
Explanation: Data abstraction can be achieved by using encapsulation. We can hide the operation
and structure of actual program from the user and can show only required information by the user.
5. Find which of the following uses encapsulation?
a) void main(){ int a; void fun( int a=10; cout<<a); fun(); }
b) class student{ int a; public: int b;};
c) class student{int a; public: void disp(){ cout<<a;} };
d) struct topper{ char name[10]; public : int marks; }
View Answer
Answer: c
Explanation: It is the class which uses both the data members and member functions being declared
inside a single unit. Only data members can be there in structures also. And the encapsulation can
only be illustrated if some data/operations are associated within class.
6. Encapsulation helps in writing ___________ classes in java
a) Mutable
b) Abstract
c) Wrapper
d) Immutable
View Answer
Answer: d
Explanation: Immutable classes are used for caching purpose generally. And it can be created by
making the class as final and making all its members private.
7. Which among the following should be encapsulated?
a) The data which is prone to change is near future
b) The data prone to change in long terms
c) The data which is intended to be changed
d) The data which belongs to some other class
View Answer
Answer: a
Explanation: The data prone to change in near future is usually encapsulated so that it doesn’t get
changed accidently. We encapsulate the data to hide the critical working of program from outside
world.
8. How can Encapsulation be achieved?
a) Using Access Specifiers
b) Using only private members
c) Using inheritance
d) Using Abstraction
View Answer
Answer: a
Explanation: Using access specifiers we can achieve encapsulation. Using this we can in turn
implement data abstraction. It’s not necessary that we only use private access.
9. Which among the following violates the principle of encapsulation almost always?
a) Local variables
b) Global variables
c) Public variables
d) Array variables
View Answer
Answer: b
Explanation: Global variables almost always violates the principles of encapsulation. Encapsulation
says the data should be accessed only by required set of elements. But global variable is accessible
everywhere, also it is most prone to changes. It doesn’t hide the internal working of program.
10. Which among the following would destroy the encapsulation mechanism if it was allowed in
programming?
a) Using access declaration for private members of base class
b) Using access declaration for public members of base class
c) Using access declaration for local variable of main() function
d) Using access declaration for global variables
View Answer
Answer: a
Explanation: If using access declaration for private members of base class was allowed in
programming, it would have destroyed whole concept of encapsulation. As if it was possible, any
class which gets inherited privately, would have been able to inherit the private members of base
class, and hence could access each and every member of base class.
11. Which among the following can be a concept against encapsulation rules?
a) Using function pointers
b) Using char* string pointer to be passed to non-member function
c) Using object array
d) Using any kind of pointer/array address in passing to another function
View Answer
Answer: d
Explanation: If we use any kind of array or pointer as data member which should not be changed,
but in some case its address is passed to some other function or similar variable. There are chances
to modify its whole data easily. Hence Against encapsulation.
12. Consider the following code and select the correct option:
class student
{
int marks;
public : int* fun()
{
return &marks;
}
};
main()
{
student s;
int *ptr=c.fun();
return 0;
}
a) This code is good to go
b) This code may result in undesirable conditions
c) This code will generate error
d) This code violates encapsulation
View Answer
Answer: d
Explanation: This code violates the encapsulation. By this code we can get the address of the
private member of the class, hence we can change the value of private member, which is against the
rules.
13. Consider the code and select the wrong choice:
class hero
{
char name[10];
public : void disp()
{
cout<<name;
}
};
a) This maintains encapsulation
b) This code doesn’t maintain encapsulation
c) This code is vulnerable
d) This code gives error
View Answer
Answer: a
Explanation: This code maintains encapsulation. Here the private member is kept private. Outside
code can’t access the private members of class. Only objects of this class will be able to access the
public member function at maximum.
14. Encapsulation is the way to add functions in a user defined structure.
a) True
b) False
View Answer
Answer: b
Explanation: False, because we can’t call these structures if member functions are involved, it must
be called class. Also, it is not just about adding functions, it’s about binding data and functions
together.
15. Using encapsulation data security is ___________
a) Not ensured
b) Ensured to some extent
c) Purely ensured
d) Very low
View Answer
Answer: b
Explanation: The encapsulation can only ensure the data security to some extent. If pointer and
addresses are misused, it may violate encapsulation. Use of global variables also makes the
program vulnerable, hence we can’t say that encapsulation gives pure security.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Abstraction”.
1. Which among the following best defines abstraction?
a) Hiding the implementation
b) Showing the important data
c) Hiding the important data
d) Hiding the implementation and showing only the features
View Answer
Answer: d
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.
2. Hiding the implementation complexity can:
a) Make the programming easy
b) Make the programming complex
c) Provide more number of features
d) Provide better features
View Answer
Answer: a
Explanation: It can make the programming easy. The programming need not know how the inbuilt
functions are working but can use those complex functions directly in the program. It doesn’t provide
more number of features or better features.
3. Class is _________ abstraction
a) Object
b) Logical
c) Real
d) Hypothetical
View Answer
Answer: b
Explanation: Class is logical abstraction because it provides a logical structure for all of its objects. It
gives an overview of the features of an object.
4. Object is ________ abstraction
a) Object
b) Logical
c) Real
d) Hypothetical
View Answer
Answer: c
Explanation: Object is real abstraction because it actually contains those features of class. It is the
implementation of overview given by class. Hence the class is logical abstraction and its object is
real.
5. Abstraction gives higher degree of ________
a) Class usage
b) Program complexity
c) Idealized interface
d) Unstable interface
View Answer
Answer: c
Explanation: It is to idealize the interface. In this way the programmer can use the programming
features more efficiently and can code better. It can’t increase the program complexity, as the
feature itself is made to hide it.
6. Abstraction can apply to:
a) Control and data
b) Only data
c) Only control
d) Classes
View Answer
Answer: a
Explanation: Abstraction applies to both. Control abstraction involves use of subroutines and control
flow abstraction. Data abstraction involves handling pieces of data in meaningful ways.
7. Which among the following can be viewed as combination of abstraction of data and code.
a) Class
b) Object
c) Inheritance
d) Interfaces
View Answer
Answer: b
Explanation: Object can be viewed as abstraction of data and code. It uses data members and their
functioning as data abstraction. Code abstraction as use of object of inbuilt class.
8. Abstraction principle includes___________
a) Use abstraction at its minimum
b) Use abstraction to avoid longer codes
c) Use abstraction whenever possible to avoid duplication
d) Use abstraction whenever possible to achieve OOP
View Answer
Answer: c
Explanation: Abstraction principle includes use of abstraction to avoid duplication (usually of code). It
this way the program doesn’t contain any redundant functions and make the program efficient.
9. Higher the level of abstraction, higher are the details.
a) True
b) False
View Answer
Answer: b
Explanation: Higher the level of abstraction, lower are the details. The best way to understand this is
to consider a whole system that is highest level of abstraction as it hides everything inside. And next
lower level would contain few of the computer components and so on.
10. Encapsulation and abstraction differ as:
a) Binding and Hiding respectively
b) Hiding and Binding respectively
c) Can be used any way
d) Hiding and hiding respectively
View Answer
Answer: a
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 the similar type of data and functions together.
11. In terms of stream and files________
a) Abstraction is called a stream and device is called a file
b) Abstraction is called a file and device is called a stream
c) Abstraction can be called both file an stream
d) Abstraction can’t be defined in terms of files and stream
View Answer
Answer: a
Explanation: Abstraction is called stream to provide a level of complexity hiding, for how the files
operations are actually done. Actual devices are called file because in one way or other, those can
be considered as single entity and there is nothing hidden.
12. If two classes combine some private data members and provides public member functions to
access and manipulate those data members. Where is abstraction used?
a) Using private access specifier for data members
b) Using class concept with both data members and member functions
c) Using public member functions to access and manipulate the data members
d) Data is not sufficient to decide what is being used
View Answer
Answer: c
Explanation: It is the concept of hiding program complexity and actual working in background. Hence
use of public member functions illustrates abstraction here.
13. A phone is made up of many components like motherboard, camera, sensors and etc. If the
processor represents all the functioning of phone, display shows the display only, and the phone is
represented as a whole. Which among the following have highest level of abstraction?
a) Motherboard
b) Display
c) Camera
d) Phone
View Answer
Answer: d
Explanation: Phone as a whole have the highest level of abstraction. This is because the phone
being a single unit represents the whole system. Whereas motherboard, display and camera are its
components.
14. Which among the following is not a level of abstraction:
a) Logical level
b) Physical level
c) View level
d) External level
View Answer
Answer: d
Explanation: Abstraction is generally divided into 3 different levels, namely, logical, physical and
view level. External level is not defined in terms of abstraction.
15. Using higher degree of abstraction __________
a) May get unsafe
b) May reduce readability
c) Can be safer
d) Can increase vulnerability
View Answer
Answer: c
Explanation: It will make the code safer. One may think it reduces the readability, but the fact is, it
actually helps us understand the code better. We don’t have to read the complex code which is of no
use in understanding the program.
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Constructors”.
1. Which among the following is called first, automatically, whenever an object is created?
a) Class
b) Constructor
c) New
d) Trigger
View Answer
Answer: b
Explanation: Constructors are the member functions which are called automatically whenever an
object is created. It is a mandatory functions to be called for an object to be created as this helps in
initializing the object to a legal initial value for the class.
2. 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
c) It must contain a definition body
d) It can contains arguments
View Answer
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.
3. Which among the following is correct?
a) class student{ public: int student(){} };
b) class student{ public: void student (){} };
c) class student{ public: student{}{} };
d) class student{ public: student(){} };
View Answer
Answer: d
Explanation: The constructors must not have any return type. Also, the body may or may not contain
any body. Defining default constructor is optional, if you are not using any other constructor.
4. In which access should a constructor be defined, so that object of the class can be created in any
function?
a) Public
b) Protected
c) Private
d) Any access specifier will work
View Answer
Answer: a
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.
5. How many types of constructors are available for use in general (with respect to parameters)?
a) 2
b) 3
c) 4
d) 5
View Answer
Answer: a
Explanation: Two types of constructors are defined generally, namely, default constructor and
parameterized constructor. Default constructor is not necessary to be defined always.
6. If a programmer defines a class and defines a default valued parameterized constructor inside it.
He has not defined any default constructor. And then he try to create the object without passing
arguments, which among the following will be correct?
a) It will not create the object (as parameterized constructor is used)
b) It will create the object (as the default arguments are passed )
c) It will not create the object ( as the default constructor is not defined )
d) It will create the object ( as at least some constructor is defined )
View Answer
Answer: b
Explanation: It will create the object without any problem, because the default arguments use the
default value if no value is passed. Hence it is equal to default constructor with zero parameters. But
it will not create the object if signature doesn’t match.
7. Default constructor must be defined, if parameterized constructor is defined and the object is to be
created without arguments.
a) True
b) False
View Answer
Answer: a
Explanation: If the object is create without arguments and only parameterized constructors are used,
compiler will give an error as there is no default constructor defined. And some constructor must be
called so as to create an object in memory.
8. If class C inherits class B. And B has inherited class A. Then while creating the object of class C,
what will be the sequence of constructors getting called?
a) Constructor of C then B, finally of A
b) Constructor of A then C, finally of B
c) Constructor of C then A, finally B
d) Constructor of A then B, finally C
View Answer
Answer: d
Explanation: While creating the object of class C, its constructor would be called by default. But, if
the class is inheriting some other class, firstly the parent class constructor will be called so that all
the data is initialized that is being inherited.
9. In multiple inheritance, if class C inherits two classes A and B as follows, which class constructor
will be called first:
class A{ };
class B{ };
class C: public A, public B{ };
a) A()
b) B()
c) C()
d) Can’t be determined
View Answer
Answer: a
Explanation: Constructor of class A will be called first. This is because the constructors in multiple
inheritance are called in the sequence in which they are written to be inherited. Here A is written first,
hence it is called first.
10. Which among the following is true for copy constructor?
a) The argument object is passed by reference
b) It can be defined with zero arguments
c) Used when an object is passed by value to a function
d) Used when a function returns an object
View Answer
Answer: b
Explanation: It can’t be defined with zero number of arguments. This is because to copy one object
to another, the object must be mentioned so that compiler can take values from that object.
11. If the object is passed by value to a copy constructor:
a) Only public members will be accessible to be copied
b) That will work normally
c) Compiler will give out of memory error
d) Data stored in data members won’t be accessible
View Answer
Answer: c
Explanation: Compiler runs out of memory. This is because while passing the argument by value, a
constructor of the object will be called. That in turn called another object constructor for values, and
this goes on. This is like a constructor call to itself, and this goes on infinite times, hence it must be
passed by reference, so that the constructor is not called.
12. Which object will be created first?
class student
{
int marks;
};
student s1, s2, s3;
a) s1 then s2 then s3
b) s3 then s2 then s1
c) s2 then s3 then s1
d) All are created at same time
View Answer
Answer: a
Explanation: The objects are created in the sequence of how they are written. This happens
because the constructors are called in the sequence of how the objects are mentioned. This is done
in sequence.
13. Which among the following helps to create a temporary instance?
a) Implicit call to a default constructor
b) Explicit call to a copy constructor
c) Implicit call to a parameterized constructor
d) Explicit call to a constructor
View Answer
Answer: d
Explanation: Explicit call to a constructor can let you create temporary instance. This is because the
temporary instances doesn’t have any name. Those are deleted from memory as soon as their
reference is removed.
14. Which among the following is correct for the class defined below?
class student
{
int marks;
public: student(){}
student(int x)
{
marks=x;
}
};
main()
{
student s1(100);
student s2();
student s3=100;
return 0;
a) Object s3, syntax error
b) Only object s1 and s2 will be created
c) Program runs and all objects are created
d) Program will give compile time error
View Answer
Answer: c
Explanation: It is a special case of constructor with only 1 argument. While calling a constructor with
one argument, you are actually implicitly creating a conversion from the argument type to the type of
class. Hence you can directly specify the value of that one argument with assignment operator.
15. For constructor overloading, each constructor must differ in ___________ and __________
a) Number of arguments and type of arguments
b) Number of arguments and return type
c) Return type and type of arguments
d) Return type and definition
View Answer
Answer: a
Explanation: Each constructor must differ in the number of arguments it accepts and the type of
arguments. This actually defines the constructor signature. This helps to remove the ambiguity and
define a unique constructor as required.

This set of Object Oriented Programming online quiz focuses on “Types of Constructors”.
1. How many types of constructors are available, in general, in any language?
a) 2
b) 3
c) 4
d) 5
View Answer
Answer: b
Explanation: There are 3 types of constructors in general, namely, default constructors,
parameterized constructors and copy constructors. Default one is called whenever an object is
created without arguments.
2. Choose the correct option for the following code.
class student
{
int marks;
}
student s1;
student s2=2;
a) Object s1 should be passed with argument.
b) Object s2 should not be declared
c) Object s2 will not be created, but program runs
d) Program gives compile time error
View Answer
Answer: d
Explanation: The object s2 can be assigned with one value only if a single argument constructor is
defined in class, but here, it can’t be done as no constructor is defined. Hence every object must be
declare or created without using arguments.
3. Which constructor is called while assigning some object with another?
a) Default
b) Parameterized
c) Copy
d) Direct assignment is used
View Answer
Answer: c
Explanation: Copy constructor is used while an object is assigned with another. This is mandatory
since we can’t decide which member should be assigned to which member value. By using copy
constructor, we can assign the values in required form.
4. It’s necessary to pass object by reference in copy constructor because:
a) Constructor is not called in pass by reference
b) Constructor is called in pass by reference only
c) It passes the address of new constructor to be created
d) It passes the address of new object to be created
View Answer
Answer: a
Explanation: Object must be passed by reference to copy constructor because constructor is not
called in pass by reference. Otherwise, in pass by value, a temporary object will be created which in
turn will try to call its constructor that is already being used. This results in creating infinite number of
objects and hence memory shortage error will be shown.
5. Which specifier applies only to the constructors?
a) Public
b) Protected
c) Implicit
d) Explicit
View Answer
Answer: d
Explanation: The keyword explicit can be used while defining the constructor only. This is used to
suppress the implicit call to the constructor. It ensures that the constructors are being called with the
default syntax only (i.e. only by using object and constructor name).
6. Which among the following is true?
a) Default constructor can’t be defined by the programmer
b) Default parameters constructor isn’t equivalent to default constructor
c) Default constructor can be called explicitly
d) Default constructor is and always called implicitly only
View Answer
Answer: c
Explanation: Default constructors can be called explicitly anytime. They are specifically used to
allocate memory space for the object in memory, in general. It is not necessary that these should
always be called implicitly.
7. Which type of constructor can’t have a return type?
a) Default
b) Parameterized
c) Copy
d) Constructors don’t have a return type
View Answer
Answer: d
Explanation: Constructors don’t return any value. Those are special functions, whose return type is
not defined, not even void. This is so because the constructors are meant to initialize the members
of class and not to perform some task which can return some value to newly created object.
8. Why do we use static constructors?
a) To initialize the static members of class
b) To initialize all the members with static value
c) To delete the static members when not required
d) To clear all the static members initialized values
View Answer
Answer: a
Explanation: Static constructors help in initializing the static members of the class. This is provided
because the static members are not considered to be property of the object, rather they are
considered as the property of class.
9. When and how many times a static constructor is called?
a) Created at time of object destruction
b) Called at first time when an object is created and only one time
c) Called at first time when an object is created and called with every new object creation
d) Called whenever an object go out of scope
View Answer
Answer: b
Explanation: Those are called at very first call of object creation. That is called only one time
because the value of static members must be retained and continued from the time it gets created.
10. Which among the following is true for static constructor?
a) Static constructors are called with every new object
b) Static constructors are used initialize data members to zero always
c) Static constructors can’t be parameterized constructors
d) Static constructors can be used to initialize the non-static members also
View Answer
Answer: c
Explanation: Static constructors can’t be parameterized constructors. Those are used to initialize the
value of static members only. And that must be a definite value. Accepting arguments may make it
possible that static members loses their value with every new object being created.
11. Within a class, only one static constructor can be created.
a) True
b) False
View Answer
Answer: a
Explanation: Since the static constructors are can’t be parameterized, they can’t be overloaded.
Having this case, only one constructor will be possible to be created in a local scope, because the
signature will always be same and hence it will not be possible to overload static constructor.
12. Default constructor initializes all data members as:
a) All numeric member with some garbage values and string to random string
b) All numeric member with some garbage values and string to null
c) All numeric member with zero and strings to random value
d) All numeric member with zero and strings to null
View Answer
Answer: d
Explanation: Default constructor, which even the programmer doesn’t define, always initialize the
values as zero if numeric and null if string. This is done so as to avoid the accidental values to
change the conditional statements being used and similar conditions.
13. When is the static constructor called?
a) After the first instance is created
b) Before default constructor call of first instance
c) Before first instance is created
d) At time of creation of first instance
View Answer
Answer: c
Explanation: The static constructor is called before creation of first instance of that class. This is
done so that even the first instance can use the static value of the static members of the class and
manipulate as required.
14. If constructors of a class are defined in private access, then:
a) The class can’t be inherited
b) The class can be inherited
c) Instance can be created only in another class
d) Instance can be created anywhere in the program
View Answer
Answer: a
Explanation: If the constructors are defined in private access, then the class can’t be inherited by
other classes. This is useful when the class contains static members only. The instances can never
be created.
15. Which among the following is correct, based on the given code below:
class student
{
int marks;
public : student()
{
cout<<”New student details can be added now”;
}
};
student s1;
a) Cout can’t be used inside the constructor
b) Constructor must contain only initilizations
c) This program works fine
d) This program produces errors
View Answer
Answer: c
Explanation: This program will work fine. This is because it is not mandatory that a constructor must
contain only initialization only. If you want to perform a task on each instance being created, that
code can be written inside the constructor.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Access Specifiers”.
1. How many types of access specifiers are provided in OOP (C++)?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: c
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.
2. Which among the following can be used together in a single class?
a) Only private
b) Private and Protected together
c) Private and Public together
d) All three together
View Answer
Answer: d
Explanation: All the classes can use any of the specifiers as needed. There is no restriction on how
many of them can be used together.
3. Which among the following can restrict class members to get inherited?
a) Private
b) Protected
c) Public
d) All three
View Answer
Answer: a
Explanation: Private members of a class can’t be inherited. These members can only be accessible
from members of its own class only. It is used to secure the data.
4. Which access specifier is used when no access specifier is used with a member of class (java)?
a) Private
b) Default
c) Protected
d) Public
View Answer
Answer: b
Explanation: Default access is used if the programmer doesn’t specify the specifier. This acts in
similar way as that of private. But since nothing is specified we call it default access.
5. Which specifier allows a programmer to make the private members which can be inherited?
a) Private
b) Default
c) Protected
d) Protected and default
View Answer
Answer: c
Explanation: Protected access is used to make the members private. But those members can be
inherited. This gives both security and code reuse capability to a program.
6. Which among the following is false?
a) Private members can be accessed using friend functions
b) Member functions can be made private
c) Default members can’t be inherited
d) Public members are accessible from other classes also
View Answer
Answer: c
Explanation: The default members can be inherited. Provided that they are in same package. It
works in a little different way from private access specifier.
7. If a class has all the private members, which specifier will be used for its implicit constructor?
a) Private
b) Public
c) Protected
d) Default
View Answer
Answer: b
Explanation: The implicit constructor will always be public. Otherwise the class wouldn’t be able to
have instances. In turn, no objects will be created and the class can only be used for inheritance.
8. If class A has add() function with protected access, and few other members in public . Then class
B inherits class A privately. Will the user will not be able to call _________ from object of class B.
a) Any function of class A
b) The add() function of class A
c) Any member of class A
d) Private, protected and public members of class A
View Answer
Answer: d
Explanation: Class B object will not be able to call any of the private, protected and public members
of class A. It is not only about the function add(), but all the members of class A will become private
members of class B.
9. Which access specifier should be used in a class where the instances can’t be created?
a) Private default constructor
b) All private constructors
c) Only default constructor to be public
d) Only default constructor to be protected
View Answer
Answer: b
Explanation: All the constructors must be made private. This will restrict the instance of class to be
made anywhere in the program. Since the constructors are private, no instance will be able to call
them and hence won’t be allocated with any memory space.
10. On which specifier’s data, does the size of a class’s object depend?
a) All the data members are added
b) Only private members are added
c) Only public members are added
d) Only default data members are added
View Answer
Answer: a
Explanation: All the data members are counted to calculate the size of an object of a class. The data
member’s access specifier doesn’t play any role here. Hence all the data size will be added.
11. If class B inherits class A privately. And class B has a friend function. Will the friend function be
able to access the private member of class A?
a) Yes, because friend function can access all the members
b) Yes, because friend function is of class B
c) No, because friend function can only access private members of friend class
d) No, because friend function can access private member of class A also
View Answer
Answer: c
Explanation: The friend function of class B will not be able to access private members of class A.
Since B is inheriting class A privately, the members will become private in class B. But private
members of class A won’t be inherited at all. Hence it won’t be accessible.
12. If an abstract class has all the private members, then _________
a) No class will be able to implement members of abstract class
b) Only single inheritance class can implement its members
c) Only other enclosing classes will be able to implement those members
d) No class will be able to access those members but can implement.
View Answer
Answer: a
Explanation: The classes which inherit the abstract class, won’t be able to implement the members
of abstract class. The private members will not be inherited. This will restrict the subclasses to
implement those members.
13. Which access specifier should be used so that all the parent class members can be inherited
and accessed from outside the class?
a) Private
b) Default or public
c) Protected or private
d) Public
View Answer
Answer: d
Explanation: All the members must be of public access. So that the members can be inherited
easily. Also, the members will be available from outside the class.
14. Which access specifier is usually used for data members of a class?
a) Private
b) Default
c) Protected
d) Public
View Answer
Answer: a
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.
15. Which specifier should be used for member functions of a class?
a) Private
b) Default
c) Protected
d) Public
View Answer
Answer: d
Explanation: It is always advised that the member functions should be kept public so that those
functions can be used from out of the class. This is usually done to ensure that the features provided
by the class can be used at its maximum.
Object Oriented Programming Questions and Answers – Private
Access Specifier
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers
(MCQs) focuses on “Private Access Specifier”.
1. If a function has to be called only by using other member functions of the class, what
should be the access specifier used for that function?
a) Private
b) Protected
c) Public
d) Default
View Answer
Answer: a
Explanation: The function should be made private. In this way, the function will be available to be
called only from the class member functions. Hence the function will be secure from outside world.
2. Which among the following is correct for the code given below?
class student
{
private: student()
{
}
public : student( int x)
{
marks =x;
}
};
a) The object can never be created
b) The object can be created without parameters
c) Only the object with only 1 parameter can be created
d) Only the object with some parameters can be created
View Answer
Answer: c
Explanation: For creating object without parameters, the default constructor must be defined in
public access. But here, only parameterized constructor is public, hence the objects being created
with only one parameter will only be allowed.
3. Which among the following is true for the code given below?
class A
{
private : int marks; char name[20];
public :
A(int x=100)
{
marks=x;
}
};
a) Objects can be created with one parameter or without parameter
b) Object can be created only with one parameter
c) Object can be created with more than one parameter
d) Objects can be create only without parameter
View Answer
Answer: a
Explanation: The constructor here has a default argument constructor. Hence we can pass one
parameter, but that is optional. If an object is created without parameter, the default value will be
used in the constructor definition.
4. Which among the following is correct to call a private member from outside the class?
a) object.memberfunction( parameters );
b) object->memberfunction( parameters );
c) object->memberfunction( parameteres); or object.memberfunction( parameters );
d) Not possible
View Answer
Answer: d
Explanation: The private member function will not be accessible from outside the class. Hence any
syntax will not work to access the private members. If you have the address of the member, may be
you can access those members, but that is totally different case and concept.
5. If private members has to be accessed directly from outside the class but the access
specifier must not be changed, what should be done?
a) Specifier must be changed
b) Friend function should be used
c) Other public members should be used
d) It is not possible
View Answer
Answer: b
Explanation: For calling the function directly, we can’t use another function because that will be
indirect call. Using friend function, we can access the private members directly.
6. Which access specifier is/are most secure during inheritance?
a) Private
b) Default
c) Protected
d) Private and default
View Answer
Answer: a
Explanation: The private members are most secure in inheritance. The default members can still be
in inherited in special cases, but the private members can’t be accessed in any case.
7. Choose the correct option for the code given below
class A{ static int c=0; public: A(){ c++; } };
a) Constructor will make c=1 for each object created
b) Constructor will make c=0 for each object created
c) Constructor will keep number of objects created
d) Constructor will just initialize c=0 then increment by 1
View Answer
Answer: c
Explanation: The constructor is using a static member to keep the count of the number of objects
created. This is done because the variable c is static and hence the value will be common for all the
objects created.
8. Which option is false for the following code?
class A
{
private : int sum(int x, int y)
{
return x+y;
}
public: A()
{
}
A(int x, int y)
{
cout&lt;&lt;sum(x,y);
}
};
a) Constructor can be created with zero argument
b) Constructor prints sum, if two parameters are passed with object creation
c) Constructor will give error if float values are passed
d) Constructor will take 0 as default value of parameters if not passed
View Answer
Answer: d
Explanation: Constructor is not having any default arguments hence no default value will be given to
any parameters. Only integer values must be passed to the constructor if we need the sum as
output, otherwise if float values are passed, type mismatch will be shown as error.
9. Which member will never be used from the following class?
class A()
{
int marks; char name[20];
public : A()
{
marks=100;
}
void disp()
{
cout&lt;&lt;”Marks= ”&lt'&lt;marks;
cout&lt;&lt;”Student”;
}
};
a) name variable will never be used
b) marks variable will never be used
c) constructor will never be used
d) disp() function will never be used
View Answer
Answer: a
Explanation: Variable name will never be used. It is a private member. None other than class
members can access name, also, neither the constructor nor the disp() function are accessing the
variable name. Hence it will never be accessible.
10. Private member functions can be overloaded.
a) True
b) False
View Answer
Answer: a
Explanation: The private functions can also be overloaded. This can be done in usual way by having
the same name of the member function and having different signature. Only thing is, they must be
accessed from members of class only.
11. Which among the following is true?
a) Private member functions can’t be overloaded
b) Private member functions can be overridden
c) Private member functions can’t be overloaded with a public member
d) Private member function can’t be overridden
View Answer
Answer: d
Explanation: The private member functions can be overloaded but they can’t be overridden. This is
because, overriding means a function with same name in derived class, gets more priority when
called from object of derived class. Here, the member function is private so there is no way that it
can be overridden.
12. Which data member in following code will be used whenever an object is created?
Class A
{
int x; int y; int z;
public : A()
{
y=100; x=100*y;
}
};
a) x will be used
b) y will be used
c) z will be used
d) All will be used
View Answer
Answer: c
Explanation: Whenever an object will be created, the constructor will be called. Inside constructor we
are using the data members x and y. Hence these two will always be used with each object creation.
13. Which member can be considered most secure in the code below?
class A()
{
int a;
private : int b;
protected : int c;
public : int d;
};
a) a
b) b
c) c
d) d
View Answer
Answer: b
Explanation: The default variables can be inherited in some special cases but the public members
can never be inherited. Hence the most secure data member in the class is b.
14. Which among the following is correct for the code given below?
class A
{
private : A()
{
}
public : A(int x)
{
}
};
A a;
A b(100);
a) Program will give compile time error
b) Program will run fine
c) Program will give runtime error
d) Program will give logical error
View Answer
Answer: a
Explanation: The program will be giving a compile time error as the default constructor is private in
class. And, the logical errors are usually runtime so we can’t say that the program will give logical
error. The program will not run.
15. Which among the following is correct?
a) Private specifier must be used before public specifier
b) Private specifier must be used before protected specifier
c) Private specifier must be used first
d) Private specifier can be used anywhere in class
View Answer
Answer: d
Explanation: The private specifier can be used anywhere in the class as required. It is not a rule to
mention the private members first and then others. It is just followed to write first for better
readability.

his set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Public Access Specifier”.
1. Which among the following is true for the code given below:
class A
{
int marks;
public : disp()
{
cout&lt;&lt;marks;
}
}
class B: protected A
{
char name[20];
}
A a; a.disp();
B b; b.disp();
a) Only object of class A can access disp() function
b) Only object of class B can access disp() function
c) Both instances can access disp() function
d) Accessing disp() outside class is not possible
View Answer
Answer: a
Explanation: The object of class A can access the disp() function. This is because the disp() function
is public in definition of class A. But it can’t be accessed from instance of class B because the disp()
function is protected in class B, since it was inherited as protected.
2. If the members have to be accessed from anywhere in program and other packages also, which
access specifier should be used?
a) Public
b) Private
c) Protected
d) Default
View Answer
Answer: a
Explanation: The access specifier must be public so as to access the members outside the class
and anywhere within the program without using inheritance. This is a rule, predefined for the public
members.
3. Which among the following have least security according to the access permissions allowed?
a) Private
b) Default
c) Protected
d) Public
View Answer
Answer: d
Explanation: The public members are available to whole program. This makes the members most
vulnerable to accidental changes, which may result in unwanted modification and hence unstable
programming.
4. Which among the following can be used for outer most class access specifier in java?
a) Private
b) Public
c) Default
d) Default or Public
View Answer
Answer: d
Explanation: Either default or public access specifier must be used for outer most classes. Private
can be used with inner classes. This is done so that all the members can access and use the
outmost class and that program execution can be done from anywhere. Inner classes can be made
private for security.
5. We can reduce the visibility of inherited methods.
a) True
b) False
View Answer
Answer: b
Explanation: The statement given is false. This is because when we inherit the members they can
either be made more secure or be at same access. But the visibility reduction is not possible, for
example, if a member is protected in parent class, then it can only be made protected or private in
sub class and not public in any case.
6. If members of a super class are public, then________
a) All those will be available in subclasses
b) None of those will be available in subclasses
c) Only data members will be available in subclass
d) Only member functions will be available in subclass
View Answer
Answer: a
Explanation: All the members will be available in sub classes. Though it is not guaranteed whether
the members will be available in subsequent subclasses from the first subclass.
7. How many public class(s) (outermost) can be there in a java program?
a) 1
b) 2
c) 3
d) As required
View Answer
Answer: a
Explanation: There can be only one public class in a java program. The public class name must
match the name of file. And there can’t be more than one class with same name in a single program
in same scope. Hence it is not possible to have more than one public class in java program.
8. What is output of following code?
package pack1;
class A
{
public A()
{
System.out.print(“object created”);
}
}
package pack2;
import pack1.*;
class B
{
A a=new A();
}
a) Output is: object created
b) Output is: object createdobject created
c) Compile time error
d) Run time error
View Answer
Answer: c
Explanation: The program will give compile time error. Class A is defined with default access
specifier. This directly means that class A will be available within package only. Even if the
constructor is public, the object will not be created.
9. Which among the following for public specifier is false?
a) The static members can’t be public
b) The public members are available in other packages tooo
c) The subclasses can inherit the public members privately
d) There can be only one public class in java program
View Answer
Answer: a
Explanation: The static members are not property of any object of the class. Instead, those are
treated as property of class. This allows us to have public static members too.
10. A class has its default constructor defined as public. Class B inherits class A privately. The class:
a) B will not be able to have instances
b) Only A can have instances
c) Only B can have instances
d) Both classes can have instances
View Answer
Answer: d
Explanation: Class A can have instances as it has public default constructor. Class will have its own
constructors defined. Hence both classes can have instances.
11. Which specifier can be used to inherit protected members as protected in sub class but public as
public in subclass?
a) Private
b) Default
c) Public
d) Protected
View Answer
Answer: c
Explanation: The specifier that can make protected member’s protected in subclass and public
member’s public in subclass, is public. This is done to maintain the security level of protected
members of parent class.
12. Which among the following is true for public class?
a) There can be more than one public class in a single program
b) Public class members can be used without using instance of class
c) Public class is available only within the package
d) Public classes can be accessed from any other class using instance
View Answer
Answer: d
Explanation: The public class is a usual class. There is no special rule but the members of the class
can be accessed from other classes using instance of the class. This is usually useful to define
main() function.
13. If a class doesn’t have public members, then________
a) None of its members will be able to get inherited
b) None of its instance creation will be allowed
c) None of its member function can be called outside the class
d) None of its data members will be able to get initial value
View Answer
Answer: c
Explanation: According to rule of private, protected and default access specifiers, none of the
members under these specifiers will be able to get invoked outside the class. We are not sure about
the members of class specifically so other options doesn’t give a fixed answer.
14. In multi-level inheritance(all public) , the public members of parent/superclass will ________
a) Will continue to get inherited subsequently
b) Will not be inherited after one subclass inheritance
c) Will not be available to be called outside class
d) Will not be able to allocated with any memory space
View Answer
Answer: a
Explanation: The public inheritance makes the public members of base class, public in derived
classes. This can be used when the same feature have to be redefined with each new class
inheriting the base class.
15. Which specifier allows to secure the public members of base class in inherited classes?
a) Private
b) Protected
c) Public
d) Private and Protected
View Answer
Answer: d
Explanation: Both the private and protected specifiers can make the public members of base class
more secure. This is useful if we stop using the parent class members and use the classes which
inherited the parent class, so as to secure data better.

his set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Data Members”.
1. What is the term used to indicate the variable and constants of a class?
a) Data members
b) Variables of class
c) Data characters
d) Constants
View Answer
Answer: a
Explanation: The variables inside a class are termed data members of the class. It is not a
mandatory rule but variables are used to refer usual variables used in functions or globally. The term
is given because the values stored in those variables represent some kind of data related to class.
2. Data members ________________ (C++)
a) Can be initialized with declaration in classes
b) Can be initialized only with help of constructors
c) Can be initialized either in declaration or by constructor
d) Can’t be initialized
View Answer
Answer: b
Explanation: The data members are not property of class, those are property of the instances of the
class. And the memory for the data members are not reserved until a constructor is called. Hence
we use constructors for their initialization after the memory is reserved.
3. Which among the following is true for data members?
a) Private data members can be initialized with declaration in class
b) Static members are initialized in constructors
c) Protected data members can be initialized in class directly
d) Static data members are defined outside class, not in constructor
View Answer
Answer: d
Explanation: Static members are not property of instances of classes. Those are shared by all the
object of classes. Hence those are defined outside the constructor, so as to make them common for
all the objects.
4. What should be done for data member to be of user defined structure type?
a) The structure must have been defined before class.
b) The structure must have been defined after the class definition
c) The structure must be predefined
d) The structure type data members can’t be used
View Answer
Answer: a
Explanation: The structure must have been defined prior to its use. If the structure is not defined,
then the memory space will not be allocated for its members. This leads to undefined use of new
data types.
5. How many data members can a class contain?
a) 27
b) 255
c) 1024
d) As many as required
View Answer
Answer: d
Explanation: Any class can have as many data members as required. The only restriction that may
arise is when there is not enough memory space. This gives flexibility to define a class with best
properties possible.
6. How to access data members of a class?
a) Dot operator
b) Arrow operator
c) Dot or arrow as required
d) Dot, arrow or direct call
View Answer
Answer: c
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.
7. To create a pointer to a private data member of a class, outside the class, which among the
following is correct?
a) Return the address of the private data member using a member function
b) Access the private member using a pointer outside class
c) Declare the member as pointer inside the class
d) Not possible to create pointer to a private member
View Answer
Answer: a
Explanation: We can call a public member function and return the address of any private data
member. Though the pointer being returned must be defined inside class itself. And the returned
address can be stored in a pointer.
8. Which among the following is true for use of setter() and getter() function?
a) Considered best for manipulating data values
b) Considered the only proper way to manipulate the values
c) Considered specially for private members manipulation
d) Considered a red flag, and not recommended for large scale use
View Answer
Answer: d
Explanation: This concept of getter and setter functions is not acceptable if used too much. This is
considered to be inappropriate in OOP perspective. Though it is commonly used, it doesn’t work
according to OOP concepts at some higher level of understanding.
9. What is the output of following code?
int n=10; // global
class A()
{
private : int n;
public : int m;
A()
{
n=100; m=50;
}
void disp()
{
cout&lt;&lt;”n”&lt;&lt;m&lt;&lt;n;
};
a) 1050100
b) 1005010
c) n5010
d) n50100
View Answer
Answer: d
Explanation: In cout we have specified n as a string to be printed. And m is a variable so its value
gets printed. And global variable will not be used since local variable have more preference.
10. The static member functions can only use ________
a) Static data members
b) Private data members
c) Protected data members
d) Constant data members
View Answer
Answer: a
Explanation: The static member functions can only access static data members. This is because the
static member function can’t work with the properties that change object to object. It is mandatory
that only the common properties of all the objects be used. And only static data members are
common to all as those are property of class.
11. A class can have self-referential data members.
a) True
b) False
View Answer
Answer: b
Explanation: The data members in a class can never refer to own class type. This is not possible
because the data members should have some memory allocated for its object before the self-
reference is used, but class must call constructor for that. Hence not possible.
12. What is the keyword used to make data members have same value?
a) static
b) const
c) double
d) abstract
View Answer
Answer: b
Explanation: The keyword const can be used anywhere to make the variable have same value all
the time. This restriction is made to use the same value whenever required. Also, this can restrict
accidental changes.
13. Which data members can be inherited but are private to a class?
a) Private
b) Protected
c) Protected and Static
d) Privately inherited
View Answer
Answer: b
Explanation: Static member’s inheritance also depends on the type of specifier they have. Only the
protected members can be inherited but remain private to class. If static members are defined in
private access, they won’t be allowed for inheritance.
14. The arguments passed to member functions by reference are considered as data members of
class.
a) True
b) False
View Answer
Answer: b
Explanation: This is a wrong statement. As only the data defined inside class is considered as its
member. But even if a variable is passed by reference it would be the same variable that is outside
the class. Hence it can’t be considered class member.
15. Which among the following is not allowed for data member declaration?
a) int a;
b) static int a;
c) abstract a;
d) Boolean a;
View Answer
Answer: c
Explanation: The abstract keyword in declaration of data members is not allowed. This is because
the abstract keyword features can’t be used with the data members of the class. We can have all
other syntax given, but not abstract.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Member Functions”.
1. Which among the following best describes member functions?
a) Functions which are defined within the class
b) Functions belonging a class
c) Functions in public access of a class
d) Functions which are private to class
View Answer
Answer: b
Explanation: We can’t say that only functions which are defined inside class are member functions.
There can be some inherited functions. Though they doesn’t belong to the class but are property of
the objects once inheritance is used. So the nearest definition is functions belonging a class.
2. How many types of member functions are generally there in C++?
a) 2
b) 3
c) 4
d) 5
View Answer
Answer: d
Explanation: There are 5 types of member functions that are generally provided in C++. Namely,
simple, static, const, inline and friend member functions. Member functions are specific to classes.
3. How can a static member function be called in main function?
a) Using dot operator
b) Using arrow operator
c) Using dot or arrow operator
d) Using dot, arrow or using scope resolution operator with class name
View Answer
Answer: d
Explanation: The member functions can be called using only the dot operator or the arrow operator.
But the static members can be called using directly the class name followed by the scope resolution
operator and static member function name. This is useful when you don’t have any object to call the
member.
4. What are inline member funcitons?
a) Member functions which can be called without object
b) Member functions whose definition is expanded in place of its call
c) Member functions whose definition is faster than simple function
d) Member function which is defined in single line
View Answer
Answer: b
Explanation: The member functions whose definition is expanded at the call, and no jump to function
and return happened, are termed as inline functions. This is used to make the program faster and
more efficient.
5. What happens if non static members are used in static member function?
a) Compile time error
b) Runtime error
c) Executes fine
d) Executes if that member function is not used
View Answer
Answer: a
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.
6. Static member functions _____________
a) Contains “this” pointer for data members
b) Contains “this” pointer if used for member functions
c) Doesn’t contain “this” pointer
d) Doesn’t contain “this” pointer if member functions are referred
View Answer
Answer: c
Explanation: The static member functions doesn’t contain “this” pointer. Static member functions
can’t be defined as const or volatile also. These are restrictions on static member functions.
7. How to access members of the class inside a member function?
a) Using this pointer only
b) Using dot operator
c) Using arrow operator
d) Used directly or with this pointer
View Answer
Answer: d
Explanation: The members of a class can be used directly inside a member function. We can use
this pointer when there is a conflict between data members of class and arguments/local function
variable names.
8. For overloading “( )”, “[ ]” or “->” operators, a class __________
a) Must use static member functions
b) Must use non-static member functions
c) Must be non-static member and should not be friend of class
d) Must use static member function or a friend member function
View Answer
Answer: c
Explanation: For overloading those operators for a class, the class must use non-static member
function so that doesn’t remain common to all the objects, and each object can use it independently.
The friend functions is also restricted so as to keep the security of data.
9. If a virtual member function is defined, ___________
a) It should not contain any body and defined by subclasses
b) It must contain body and overridden by subclasses
c) It must contain body and be overloaded
d) It must not contain any body and should not be derived
View Answer
Answer: a
Explanation: The virtual functions are defined using virtual keyword. These are made in order to
make all the classes to define them as the class gets inherited. Increases code understanding.
10. Member functions of a generic class are _____________
a) Not generic
b) Automatically generic
c) To be made generic explicitly
d) Given default type as double
View Answer
Answer: b
Explanation: When generic type is used in a class, the functions are automatically generic. This is so
because the functions would use the same type as defined to make the class generic. The functions
will get to know the type of data as soon as the generic class is used. It’s inbuilt feature.
11. Member function of a class can ____________
a) Access all the members of the class
b) Access only Public members of the class
c) Access only the private members of the class
d) Access subclass members
View Answer
Answer: a
Explanation: The member functions has access to all the members of the class. Whenever data
members of a class, which might be private, have to be modified, we make use of these member
functions. This is more secure way to manipulate data.
12. Which among the following is proper syntax for class given below?
class A
{
int a,b;
public : void disp();
}
a) void disp::A(){ }
b) void A::disp(){ }
c) void A:disp() { cout<<a<<b ; }
d) void disp:A(){ cout<<a<<b; }
View Answer
Answer: b
Explanation: The syntax in option b is correct. We use scope resolution to represent the member
function of a class and to write its definition. It is not necessary for a function to have anything in its
definition.
13. A member function can _______________ of the same class
a) Call other member functions
b) Call only private member functions
c) Call only static member functions
d) Call only const member funcitons
View Answer
Answer: a
Explanation: We can call one function inside another function to access some data of class. A public
member function can be used to call a private member function which directly manipulates the
private data of class.
14. Which member function doesn’t require any return type?
a) Static
b) Constructor
c) Const
d) Constructor and destructor
View Answer
Answer: d
Explanation: All the member functions work same as normal functions with syntax. But the
constructor and destructor are also considered as member functions of a class, and they never have
any data type.
15. Which among the following is not possible for member function?
a) Access protected members of parent class
b) Definition without return type
c) Access public members of subclass
d) Access static members of class
View Answer
Answer: c
Explanation: A member function of a class can only have the access to the members of its own class
and parent classes if inheritance used. Otherwise a member function can never access the
members of a subclass. Accessing static members of a class is possible by normal and static
member functions.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Local Class”.
1. What are local classes?
a) Classes declared inside a package
b) Classes declared inside a function
c) Classes declared inside a class
d) Classes declared inside structure
View Answer
Answer: b
Explanation: The classes declared inside a package are available to all the functions and classes,
hence can’t be called local. This is somewhat similar concept that we use to denote variables of a
function. The classes declared inside functions will be local to them.
2. All member functions of a local class must be ___________
a) Defined outside class body
b) Defined outside the function definition
c) Defined inside the class body
d) Defined at starting of program
View Answer
Answer: c
Explanation: There is a restriction on where the member functions of the local class should be
define. Those must be defined inside the class body only. This is to reduce the ambiguity and
complexity of program.
3. Can local class members access/use the general local variables (except static, abstract etc.) of
the function in which it is defined?
a) Yes, it can access with arrow operator
b) No, it can’t access with dot operator
c) Yes, it can access using dot operator
d) No, it can’t access In anyway
View Answer
Answer: d
Explanation: The local variables of the functions are not available to the member functions of the
class. This is done to reduce the ambiguity in variables and their access rules.
4. Which type of data can a local class access from the function in which it is defined?
a) Static and extern
b) Abstract and static
c) Void and extern
d) Const and static
View Answer
Answer: a
Explanation: The local classes have this feature to access the static and extern variables of the
function in which those are defined. This feature is available since these type of data are common to
the program and is created only one time. Run time creation and destruction of these variables is not
done. The only restriction that may apply is those members must be constants.
5. Local classes can access the type names and enumerators defined by the enclosing function.
a) True
b) False
View Answer
Answer: a
Explanation: This is a little tricky part with local classes. Though the local class can’t access the
general variables of the function but can access the types that are defined inside the function. This is
because the whole definition of that type would be existing inside the class.
6. Can static variables be declared inside a local class?
a) Yes, with public access specifier
b) Yes, anywhere as required
c) No, not possible in private access specifier
d) No, not possible anyway
View Answer
Answer: d
Explanation: No, the static variables can’t be declared inside a local class. This is because each time
the function is called, all the variables get created again and are destroyed as soon as the function is
returned. This would have been possible id the static variable was of function.
7. All the member functions of local classes are __________ by default.
a) Static
b) Inline
c) Abstract
d) Virtual
View Answer
Answer: c
Explanation: All the members are defined inside the class body. And when the member functions are
defined inside the class body, they are made inline by default. If the definition is too complex, those
are made normal functions.
8. The enclosing function has no special access to the members of local class. (True/False)
a) True
b) False
View Answer
Answer: a
Explanation: This is a rule that the enclosing function doesn’t have any special access to the
members of local class. This is done to maintain the security of class members. And to adhere to the
rules of OOP.
9. Which language can use inheritance with local classes?
a) Kotlin
b) Java
c) SmallTalk
d) SAP ABAP
View Answer
Answer: d
Explanation: Other language might support inheritance with local classes but those doesn’t provide
all the proper features of inheritance. Language SAP ABAP provides a way to implement inheritance
with local classes efficiently.
10. How many local classes can be defined inside a single function?
a) Only 1
b) Only 3
c) Only 5
d) As many as required
View Answer
Answer: d
Explanation: The local classes can be defined as required. There is no restriction on the number of
local classes that can be defined inside a function. But all those classes must follow the rules and
restrictions.
11. All the data members of local class must be ___________
a) Defined with declaration
b) Defined in constructor
c) Declared and defined in constructor
d) Declared using a member function
View Answer
Answer: b
Explanation: The data members follow same rules as of simple classes. Hence the data members
must be declared first. Then their definition must be given using the constructors.
12. Can two different functions have local class with same name?
a) Yes, since local
b) No, names must be different
c) No, scope doesn’t work here
d) No, ambiguity arises
View Answer
Answer: a
Explanation: The local classes can have same name if they belong to different functions. The
classes would be local to those specific functions and hence can have same name. This is same as
that of local variables concept.
13. What is the scope of local class?
a) Within the class only
b) Within the function
c) Within the program
d) One time creation and live till end of program
View Answer
Answer: b
Explanation: The scope of a local class is limited only within the function definition. The function can
use the class as usual as local variables. The class gets destroyed as soon as the function is
returned.
14. Can a function, other than the enclosing function of local class, access the class members?
a) Yes, using object
b) Yes, using direct call
c) Yes, using pointer
d) No, can’t access
View Answer
Answer: d
Explanation: The local classes are local to the specific enclosing function. Other functions can’t
access the class. Even if the pointers are used, the class must be alive when the pointer is used. But
this will not happen if the enclosing function is returned.
15. Which among the following is main advantage of using local classes?
a) Make program more efficient
b) Makes program execution faster
c) Helps to add extra functionality to a function
d) Helps to add more members to a function
View Answer
Answer: c
Explanation: The closest answer is to add more functionalities to a function or to make some specific
functions to be generic. Adding more members to a function can be done directly but to add some
special functionality that are encapsulated, can be done using local classes.
his set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Nested Class”.
1. Which among the following best describes a nested class?
a) Class inside a class
b) Class inside a function
c) Class inside a package
d) Class inside a structure
View Answer
Answer: a
Explanation: If a class is defined inside another class, the inner class is termed as nested class. The
inner class is local to the enclosing class. Scope matters a lot here.
2. Which feature of OOP reduces the use of nested classes?
a) Encapsulation
b) Inheritance
c) Binding
d) Abstraction
View Answer
Answer: b
Explanation: Using inheritance we can have the security of the class being inherited. The sub class
can access the members of parent class. And have more feature than a nested class being used.
3. How many categories are nested classes divided into?
a) 2
b) 3
c) 4
d) 5
View Answer
Answer: a
Explanation: The nested classes are divided into two main categories. Namely, Static and non-static.
The categories define how the classes can be used inside another class.
4. Non-static nested classes have access to _____________ from enclosing class.
a) Private members
b) Protected members
c) Public members
d) All the members
View Answer
Answer: d
Explanation: The non-static nested class can access all the members of the enclosing class. All the
data members and member functions can be accessed from the nested class. Even if the members
are private, they can be accessed.
5. Static nested classes doesn’t have access to _________________ from enclosing class.
a) Private members
b) Protected members
c) Public members
d) Any other members
View Answer
Answer: d
Explanation: The static nested class doesn’t have access to any other members of the enclosing
class. This is a rule that is made to ensure that only the data which can be common to all the object
is being accessed by the static nested class.
6. The nested class can be declared ___________________
a) Public
b) Private
c) Protected
d) Public, Protected, Private or Package private
View Answer
Answer: d
Explanation: The nested class can be declared with any specifier, unlike the outer classes which can
only be declared public or package private. This is a flexibility given for the nested class being a
member of enclosing class.
7. Use of nested class ____________ encapsulation.
a) Increases
b) Decreases
c) Doesn’t affect
d) Slightly decreases
View Answer
Answer: a
Explanation: The use of nested class increases encapsulation as the inner class is getting even
more grouped into the enclosing class. Firstly the class encapsulate the data, having nested classes
can increase the encapsulation even further.
8. Which among the following is correct advantage/disadvantage of nested classes?
a) Makes the code more complex
b) Makes the code unreadable
c) Makes the code efficient and readable
d) Makes the code multithreaded
View Answer
Answer: c
Explanation: The use of nested classes make the code more streamed towards a single concept.
This allows to group the most similar and related classes together and makes it even more efficient
and readable.
9. How to access static nested classes?
a) OuterClass.StaticNestedClass
b) OuterClass->StaticNestedClass
c) OuterClass(StaticNestedClass)
d) OuterClass[StaticNestedClass].
View Answer
Answer: a
Explanation: Like any other member of the class, the static nested class uses the dot operator to be
accessed. The reason behind is, the static classes can’t work with instances, hence we use
enclosing class name to access static nested class.
10. A nested class can have its own static members.
a) True
b) False
View Answer
Answer: b
Explanation: The nested classes are associated with the object of the enclosing class. Hence have
direct access to the members of that object. Hence the inner class can’t have any static members of
its own. Otherwise the rule of static members would be violated using enclosing class instance.
11. How to create object of the inner class?
a) OuterClass.InnerClass innerObject = outerObject.new InnerClass();
b) OuterClass.InnerClass innerObject = new InnerClass();
c) InnerClass innerObject = outerObject.new InnerClass();
d) OuterClass.InnerClass = outerObject.new InnerClass();
View Answer
Answer: a
Explanation: An instance of inner class can exist only within instance of outer class. To instantiate
the inner class, one must instantiate the outer class first. This can be done by the correct syntax
above.
12. What will be the output of the following code?
public class Test
{
public int a=0;
class innerClass
{
public int a=1;
void innermethod(int x)
{
System.out.println(“value of x = ” + x);
System.out.println(“value of this.x = ” + this.x);
System.out.println(“value of Test.this.x = ” +
Test.T=this.x);
}
}
}
public static void main( String args[] )
{
Test t=new Test();
Test.innerClass im=t.new innerClass();
im.innermethod(55);
}
a) value of x = 55
value of this.x = 0
value of Test.this.x = 1
b) value of x = 1
value of this.x = 0
value of Test.this.x = 55
c) value of x = 55
value of this.x = 1
value of Test.this.x = 0
d) value of x = 0
value of this.x = 55
value of Test.this.x = 1
View Answer
Answer: c
Explanation: The variable x denotes the parameter of the function. And this.x is the variable of the
inner class. Test.this.x is the variable of the outer class. Hence we get this output.
13. Instance of inner class can exist only _______________ enclosing class.
a) Within
b) Outside
c) Private to
d) Public to
View Answer
Answer: a
Explanation: The class defined inside another class is local to the enclosing class. This means that
the instance of inner class will not be valid outside the enclosing class. There is no restriction for
instance to be private or public always.
14. If a declaration of a member in inner class has the same name as that in the outer class, then
________________ enclosing scope.
a) Outer declaration shadows inner declaration in
b) Inner declaration shadows outer declaration in
c) Declaration gives compile time error
d) Declaration gives run time error
View Answer
Answer: b
Explanation: The inner class will have more preference for its local members than those of the
enclosing members. Hence it will shadow the enclosing class members. This process is known as
shadowing.
15. A static nested class is _____________ class in behavior that is nested in another _________
class.
a) Top level, top level
b) Top level, low level
c) Low level, top level
d) Low level, low level
View Answer
Answer: a
Explanation: Top level class encloses the other classes or have same preference as that of other top
level classes. Having a class inside the top level class is indirectly having a top level class which
higher degree of encapsulation.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Nested Class”.
1. Which among the following best describes a nested class?
a) Class inside a class
b) Class inside a function
c) Class inside a package
d) Class inside a structure
View Answer
Answer: a
Explanation: If a class is defined inside another class, the inner class is termed as nested class. The
inner class is local to the enclosing class. Scope matters a lot here.
2. Which feature of OOP reduces the use of nested classes?
a) Encapsulation
b) Inheritance
c) Binding
d) Abstraction
View Answer
Answer: b
Explanation: Using inheritance we can have the security of the class being inherited. The sub class
can access the members of parent class. And have more feature than a nested class being used.
3. How many categories are nested classes divided into?
a) 2
b) 3
c) 4
d) 5
View Answer
Answer: a
Explanation: The nested classes are divided into two main categories. Namely, Static and non-static.
The categories define how the classes can be used inside another class.
4. Non-static nested classes have access to _____________ from enclosing class.
a) Private members
b) Protected members
c) Public members
d) All the members
View Answer
Answer: d
Explanation: The non-static nested class can access all the members of the enclosing class. All the
data members and member functions can be accessed from the nested class. Even if the members
are private, they can be accessed.
5. Static nested classes doesn’t have access to _________________ from enclosing class.
a) Private members
b) Protected members
c) Public members
d) Any other members
View Answer
Answer: d
Explanation: The static nested class doesn’t have access to any other members of the enclosing
class. This is a rule that is made to ensure that only the data which can be common to all the object
is being accessed by the static nested class.
6. The nested class can be declared ___________________
a) Public
b) Private
c) Protected
d) Public, Protected, Private or Package private
View Answer
Answer: d
Explanation: The nested class can be declared with any specifier, unlike the outer classes which can
only be declared public or package private. This is a flexibility given for the nested class being a
member of enclosing class.
7. Use of nested class ____________ encapsulation.
a) Increases
b) Decreases
c) Doesn’t affect
d) Slightly decreases
View Answer
Answer: a
Explanation: The use of nested class increases encapsulation as the inner class is getting even
more grouped into the enclosing class. Firstly the class encapsulate the data, having nested classes
can increase the encapsulation even further.
8. Which among the following is correct advantage/disadvantage of nested classes?
a) Makes the code more complex
b) Makes the code unreadable
c) Makes the code efficient and readable
d) Makes the code multithreaded
View Answer
Answer: c
Explanation: The use of nested classes make the code more streamed towards a single concept.
This allows to group the most similar and related classes together and makes it even more efficient
and readable.
9. How to access static nested classes?
a) OuterClass.StaticNestedClass
b) OuterClass->StaticNestedClass
c) OuterClass(StaticNestedClass)
d) OuterClass[StaticNestedClass].
View Answer
Answer: a
Explanation: Like any other member of the class, the static nested class uses the dot operator to be
accessed. The reason behind is, the static classes can’t work with instances, hence we use
enclosing class name to access static nested class.
10. A nested class can have its own static members.
a) True
b) False
View Answer
Answer: b
Explanation: The nested classes are associated with the object of the enclosing class. Hence have
direct access to the members of that object. Hence the inner class can’t have any static members of
its own. Otherwise the rule of static members would be violated using enclosing class instance.
11. How to create object of the inner class?
a) OuterClass.InnerClass innerObject = outerObject.new InnerClass();
b) OuterClass.InnerClass innerObject = new InnerClass();
c) InnerClass innerObject = outerObject.new InnerClass();
d) OuterClass.InnerClass = outerObject.new InnerClass();
View Answer
Answer: a
Explanation: An instance of inner class can exist only within instance of outer class. To instantiate
the inner class, one must instantiate the outer class first. This can be done by the correct syntax
above.
12. What will be the output of the following code?
public class Test
{
public int a=0;
class innerClass
{
public int a=1;
void innermethod(int x)
{
System.out.println(“value of x = ” + x);
System.out.println(“value of this.x = ” + this.x);
System.out.println(“value of Test.this.x = ” +
Test.T=this.x);
}
}
}
public static void main( String args[] )
{
Test t=new Test();
Test.innerClass im=t.new innerClass();
im.innermethod(55);
}
a) value of x = 55
value of this.x = 0
value of Test.this.x = 1
b) value of x = 1
value of this.x = 0
value of Test.this.x = 55
c) value of x = 55
value of this.x = 1
value of Test.this.x = 0
d) value of x = 0
value of this.x = 55
value of Test.this.x = 1
View Answer
Answer: c
Explanation: The variable x denotes the parameter of the function. And this.x is the variable of the
inner class. Test.this.x is the variable of the outer class. Hence we get this output.
13. Instance of inner class can exist only _______________ enclosing class.
a) Within
b) Outside
c) Private to
d) Public to
View Answer
Answer: a
Explanation: The class defined inside another class is local to the enclosing class. This means that
the instance of inner class will not be valid outside the enclosing class. There is no restriction for
instance to be private or public always.
14. If a declaration of a member in inner class has the same name as that in the outer class, then
________________ enclosing scope.
a) Outer declaration shadows inner declaration in
b) Inner declaration shadows outer declaration in
c) Declaration gives compile time error
d) Declaration gives run time error
View Answer
Answer: b
Explanation: The inner class will have more preference for its local members than those of the
enclosing members. Hence it will shadow the enclosing class members. This process is known as
shadowing.
15. A static nested class is _____________ class in behavior that is nested in another _________
class.
a) Top level, top level
b) Top level, low level
c) Low level, top level
d) Low level, low level
View Answer
Answer: a
Explanation: Top level class encloses the other classes or have same preference as that of other top
level classes. Having a class inside the top level class is indirectly having a top level class which
higher degree of encapsulation.
This set of Object Oriented Programming test focuses on “Memory Allocation of Object”.
1. What does memory allocation for objects mean?
a) Actual creation and memory allocation for object members
b) Creation of member functions
c) Creation of data members for a class
d) Actual creation and data declaration for object members
View Answer
Answer: a
Explanation: The memory allocated for the object members indicates actual creation of the object
members. This is known as memory allocation for object.
2. Where is the memory allocated for the objects?
a) HDD
b) Cache
c) RAM
d) ROM
View Answer
Answer: c
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.
3. When is the memory allocated for an object?
a) At declaration of object
b) At compile time
c) When object constructor is called
d) When object is initialized to another object
View Answer
Answer: c
Explanation: The object memory allocation takes place when the object constructor is called.
Declaration of an object doesn’t mean that memory is allocated for its members. If object is initialized
with another object, it may just get a reference to the previously created object.
4. Using new is type safe as _______________________
a) It require to be specified with type of data
b) It doesn’t require to be specified with type of data
c) It requires the name of data
d) It allocated memory for the data
View Answer
Answer: b
Explanation: The new is type safe because we don’t have to specify the type of data that have to be
allocated with memory. We can directly use it with data name. Name of the data doesn’t matter
though for type of memory allocation though.
5. Which of the following function can be used for dynamic memory allocation of objects?
a) malloc()
b) calloc()
c) create()
d) malloc() and calloc()
View Answer
Answer: d
Explanation: The malloc() function can be used to allocate dynamic memory for objects. Function
calloc() can also be use. These functions differ in the way they allocate memory for objects.
6. How much memory will be allocated for an object of class given below?
class Test
{
int mark1;
int mark2;
float avg;
char name[10];
};
a) 22 Bytes
b) 24 Bytes
c) 20 Bytes
d) 18 Bytes
View Answer
Answer: a
Explanation: The size of an object of the class given in question will be of size 22 bytes. This is
because the size of an object is always equal to the sum of sizes of the data members of the class,
except static members.
7. Which keyword among the following can be used to declare an array of objects in java?
a) new
b) create
c) allocate
d) arr
View Answer
Answer: a
Explanation: The keyword new can be used to declare an array of objects in java. The syntax must
be 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.
8. When is the memory allocated for an object gets free?
a) At termination of program
b) When object goes out of scope
c) When main function ends
d) When system restarts
View Answer
Answer: b
Explanation: Whenever an object goes out of scope, the deletion of allocation memory takes place.
Actually the data is not deleted, instead the memory space is flagged to be free for further use.
Hence whenever an object goes out of scope the object members become useless and hence
memory is set free.
9. Which among the following keyword can be used to free the allocated memory for an object?
a) delete
b) free
c) either delete or free
d) only delete
View Answer
Answer: c
Explanation: The memory allocated for an object is usually automatically made free. But if explicitly
memory has to be made free then we can use either free or delete keywords depending on
programming languages.
10. Which function is called whenever an object goes out of scope?
a) Destructor function
b) Constructor function
c) Delete function
d) Free function
View Answer
Answer: a
Explanation: The destructor function of the class is called whenever an object goes out of scope.
This is because the destructor set all the resources, acquired by the object, free. This is an implicit
work of compiler.
11. Which operator can be used to check the size of an object?
a) sizeof(objectName)
b) size(objectName)
c) sizeofobject(objectName)
d) sizedobject(objectName)
View Answer
Answer: a
Explanation: The sizeof operator is used to get the size of an already created object. This operator
must constail keyword sizeof(objectName). The output will give the number of bytes acquired by a
single object of some class.
12. The memory allocated for an object ____________________
a) Can be only dynamic
b) Can be only static
c) Can be static or dynamic
d) Can’t be done using dynamic functions
View Answer
Answer: c
Explanation: The memory allocation for an object can be static or dynamic. The static memory
allocation is when an object is declared directly without using any function usually. And dynamic
allocation is when we use some dynamic allocation function to allocate memory for data member of
an object.
13. If an object is declared in a user defined function __________________
a) Its memory is allocated in stack
b) Its memory is allocated in heap
c) Its memory is allocated in HDD
d) Its memory is allocated in cache
View Answer
Answer: a
Explanation: The memory for any data or object that are used in a user defined function are always
allocated in the stack. This is to ensure that the object is destroyed as soon as the function is
returned. Also this ensures that the correct memory allocation and destruction is performed.
14. In java, ____________________ takes care of managing memory for objects dynamically.
a) Free collector
b) Dust collector
c) Memory manager
d) Garbage collector
View Answer
Answer: d
Explanation: The garbage collector in java takes care of the memory allocations and their deletions
dynamically. When an object is no more required then the garbage collector deletes the object and
free up all the resources that were held by that object.
15. Which operator can be used to free the memory allocated for an object in C++?
a) Free()
b) delete
c) Unallocate
d) Collect
View Answer
Answer: b
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++.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Abstract Class”.
1. Which among the following best describes abstract classes?
a) If a class has more than one virtual function, it’s abstract class
b) If a class have only one pure virtual function, it’s abstract class
c) If a class has at least one pure virtual function, it’s abstract class
d) If a class has all the pure virtual functions only, then it’s abstract class
View Answer
Answer: c
Explanation: The condition for a class to be called abstract class is that it must have at least one
pure virtual function. The keyword abstract must be used while defining abstract class in java.
2. Can abstract class have main() function defined inside it?
a) Yes, depending on return type of main()
b) Yes, always
c) No, main must not be defined inside abstract class
d) No, because main() is not abstract function
View Answer
Answer: b
Explanation: This is a property of abstract class. It can define main() function inside it. There is no
restriction on its definition and implementation.
3. If there is an abstract method in a class then, ________________
a) Class must be abstract class
b) Class may or may not be abstract class
c) Class is generic
d) Class must be public
View Answer
Answer: a
Explanation: It is a rule that if a class have even one abstract method, it must be an abstract class. If
this rule was not made, the abstract methods would have got skipped to get defined in some places
which is undesirable with the idea of abstract class.
4. If a class is extending/inheriting any other abstract class having abstract method, then
_______________________
a) Either implementation of method or making class abstract is mandatory
b) Implementation of the method in derived class is mandatory
c) Making the derived class also abstract is mandatory
d) It’s not mandatory to implement the abstract method of parent class
View Answer
Answer: a
Explanation: Either of the two things must be done, either implementation or declaration of class as
abstract. This is done to ensure that the method intended to be defined by other classes gets
defined at every possible class.
5. Abstract class A has 4 virtual functions. Abstract class B defines only 2 of those member functions
as it extends class A. Class C extends class B and implements the other two member functions of
class A. Choose the correct option below.
a) Program won’t run as all the methods are not defined by B
b) Program won’t run as C is not inheriting A directly
c) Program won’t run as multiple inheritance is used
d) Program runs correctly
View Answer
Answer: d
Explanation: The program runs correctly. This is because even class B is abstract so it’s not
mandatory to define all the virtual functions. Class C is not abstract but all the virtual functions have
been implemented will that class.
6. Abstract classes can ____________________ instances.
a) Never have
b) Always have
c) Have array of
d) Have pointer of
View Answer
Answer: a
Explanation: When an abstract class is defined, it won’t be having implementation of at least one
function. This will restrict the class to have any constructor. When the class doesn’t have
constructor, there won’t be any instance of that class.
7. We ___________________ to an abstract class.
a) Can create pointers
b) Can create references
c) Can create pointers or references
d) Can’t create any reference, pointer or instance
View Answer
Answer: c
Explanation: Even though there can’t be any instance of abstract class. We can always create
pointer or reference to abstract class. The member functions which have some implementation
inside abstract itself, can be used with these references.
8. Which among the following is an important use of abstract classes?
a) Header files
b) Class Libraries
c) Class definitions
d) Class inheritance
View Answer
Answer: b
Explanation: The abstract classes can be used to create a generic, extensible class library that can
be used by other programmers. This helps us to get some already implemented codes and functions
that might have not been provided by the programming language itself.
9. Use of pointers or reference to an abstract class gives rise to which among the following feature?
a) Static Polymorphism
b) Run time polymorphism
c) Compile time Polymorphism
d) Polymorphism within methods
View Answer
Answer: b
Explanation: The run time polymorphism is supported by reference and pointer to an abstract class.
This relies upon base class pointer and reference to select the proper virtual function.
10. The abstract classes in java can _________________
a) Implement constructors
b) Can’t implement constructor
c) Can implement only unimplemented methods
d) Can’t implement any type of constructor
View Answer
Answer: a
Explanation: The abstract classes in java can define a constructor. Even though instance can’t be
created. But in this way, only during constructor chaining, constructor can be called. When instance
of concrete implementation class is created, it’s known as constructor chaining.
11. Abstract class can’t be final in java.
a) True
b) False
View Answer
Answer: a
Explanation: If an abstract class is made final in java, it will stop the abstract class from being
extended. And if the class is not getting extended, there won’t be any other class to implement the
virtual functions. Due to this contradicting fact, it can’t be final in java.
12. Can abstract classes have static methods (Java)?
a) Yes, always
b) Yes, but depends on code
c) No, never
d) No, static members can’t have different values
View Answer
Answer: a
Explanation: There is no restriction on declaring static methods. The only condition is that the virtual
functions must have some definition in program.
13. It is _________________________ to have an abstract method.
a) Not mandatory for an static class
b) Not mandatory for a derived class
c) Not mandatory for an abstract class
d) Not mandatory for parent class
View Answer
Answer: c
Explanation: Derived, parent and static classes can’t have abstract method (We can’t say what type
of these classes is). And for abstract class it’s not mandatory to have abstract method. But if any
abstract method is there inside a class, then class must be abstract type.
14. How many abstract classes can a single program contain?
a) At most 1
b) At least 1
c) At most 127
d) As many as required
View Answer
Answer: d
Explanation: There is no restriction on the number of abstract classes that can be defined inside a
single program. The programs can use as many abstract classes as required. But the functions with
no body must be implemented.
15. Is it necessary that all the abstract methods must be defined from an abstract class?
a) Yes, depending on code
b) Yes, always
c) No, never
d) No, if function is not used, no definition is required
View Answer
Answer: b
Explanation: That is rule of programming language that each function declared, must have some
definition. There can’t be some abstract method that remains undefined. Even if it’s there, it would
result in compile time error.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Derived Class”.
1. Which among the following is best definition of a derived class?
a) A child class
b) A class which inherits one or more classes
c) A class with keyword derived
d) A class with more than one constructor
View Answer
Answer: b
Explanation: Any class which inherits one or more classes is a derived class. The only condition is it
must inherit at least one class in order to be called as a derived class.
2. Which among the following is inherited by a derived class from base class?
a) Data members only
b) Member functions only
c) All the members except private members
d) All the members of base class
View Answer
Answer: c
Explanation: The class inheriting another class, inherits all the data members and member functions
which are not private. This is done to ensure the security features with maximum flexibility.
3. If there is a derived class in a program, how many classes must be in that program?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: b
Explanation: If there is a derived class in a program, there must be at least 2 classes in that
program. One is a base class and another derived class. Hence at least 2 classes must be there.
4. Which members can never be accessed in derived class from the base class?
a) Private
b) Protected
c) Public
d) All except private
View Answer
Answer: d
Explanation: There is no restriction for a derived class to access the members of the base class until
and unless the members are private. Private member are declared so that those members are not
accessible outside the class.
5. How many types of inheritance are supported in C++ for deriving a class?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: c
Explanation: There are three types of inheritance possible. Private inheritance, protected
inheritance, and public inheritance. The inheritance defines the access specifier to be used with the
inherited members in the derived class.
6. How many derived class can a single base class have?
a) 1
b) 2
c) 3
d) As many are required
View Answer
Answer: d
Explanation: There is no restriction on how many classes can inherit a single base class. Hence
there can be as many derived classes as required in a program from a single base class.
7. Which among the following is correct?
a) Friend function of derived class can access non-private members of base class
b) Friend function of base class can access derived class members
c) Friend function of derived class can access members of only derived class
d) Friend function can access private members of base class of a derived class
View Answer
Answer: a
Explanation: The friend function of a class can access the non-private members of base class. The
reason behind is that the members of base class gets derived into the derived class and hence
become members of derived class too. Hence a friend function can access all of those.
8. If a class is being derived using more than two base classes, which inheritance will be used?
a) Single
b) Multi-level
c) Hierarchical
d) Multiple
View Answer
Answer: d
Explanation: The statement given is definition of multiple inheritance with respect to the derived
class. The concept can be illustrated with many other samples but the main aspects are base class
and derived class only.
9. Derived class is also known as ______________ class.
a) Subclass
b) Small class
c) Big class
d) Noticeable class
View Answer
Answer: a
Explanation: It is just another name given to the derived classes. This is used while denoting all the
derived classes subsequent to a super class.
10. If class A is derived from another derived class B which is derived from class C, which class will
have maximum level of abstraction?
a) Class A
b) Class B
c) Class C
d) All have same level of abstraction
View Answer
Answer: c
Explanation: The abstraction level of class C will be maximum. This is because the parent class
have higher level of abstraction. Hence the parent of all other class will have maximum level of
abstraction.
11. If base class is an abstract class then derived class ______________ the undefined functions.
a) Must define
b) Must become another abstract class or define
c) Must become parent class for
d) Must implement 2 definitions of
View Answer
Answer: b
Explanation: The function must be defined in the program which are not defined in the base class.
Hence the class must be defined as abstract of implement the function definition in it.
12. How many classes can be derived from a derived class?
a) Only 1
b) At most 1
c) At least 1
d) As many as required
View Answer
Answer: d
Explanation: When a class is to be derived from another derived class, the derived class behaves as
a normal base class hence there are no restriction on how many class can be derived from a derived
class. The derived class again behaves as a normal super class.
13. The members of a derived class can never be derived.
a) True
b) False
View Answer
Answer: b
Explanation: This is not true that the members of a derived class can’t be derived. All the classes are
considered to be a normal class when used for derivation. The members can be derived with respect
to their access specifiers.
14. Which feature is not related to the derived classes among the following?
a) Inheritance
b) Encapsulation
c) Run time memory management
d) Compile time function references
View Answer
Answer: c
Explanation: The memory management is the feature that is not necessary for derived classes that
will be a part of whole program. The functions references must be resolved for their proper use if
inheritance is used.
15. Deriving a class in such a way that that the base class members are not available for further
inheritance is known as ___________________
a) Public inheritance
b) Protected inheritance
c) Protected or private inheritance
d) Private inheritance
View Answer
Answer: d
Explanation: The private members of a class can never be derived to another class. When a class
derives another class using private inheritance, all the members become private members of the
derived class. Hence these member won’t be available for further inheritance.
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Template Class”.
1. A template class can have _____________
a) More than one generic data type
b) Only one generic data type
c) At most two data types
d) Only generic type of integers and not characters
View Answer
Answer: a
Explanation: The template class can support more than one data type. The only thing is to add all
the data types required in a list separated by comma within template specification.
2. Which among the following is the proper syntax for the template class?
a) template ;
b) Template ;
c) template T named(T x, T y){ }
d) Template T1 named(T1 x, T2 y){ }
View Answer
Answer: c
Explanation: The syntax must start with keyword template, case sensitive. Then it should include the
typename and a variable to denote it. Then whenever that variable is used, it replaces it with the
data type needed.
3. Can default arguments be used with the template class?
a) Yes, in some special cases
b) Yes, always
c) No, it must satisfy some specific conditions first
d) No, it can’t be done
View Answer
Answer: b
Explanation: The template class can use default arguments. This is used to specify the data type to
be considered if it is not specified while passing to the generic class. The default type will be used.
4. What is the syntax to use explicit class specialization?
a) template class myClass<>{ }
b) template class myClass{ }
c) template <> class myClass<>{ }
d) template <> class myClass{ }
View Answer
Answer: d
Explanation: The class specialization is creation of explicit specialization of a generic class. We have
to use template<> constructor for this to work. It works in the same way as with explicit function
specialization.
5. Which is the most significant feature that arises by using template classes?
a) Code readability
b) Ease in coding
c) Code reusability
d) Modularity in code
View Answer
Answer: c
Explanation: The code reusability is the feature that becomes more powerful with use of template
classes. You can generate a single code that can be used in variety of programming situation.
6. A template class defines the form of a class _____________________ it will operate.
a) With full specification of the data on which
b) With full specification of the functions on which
c) Without full specification of the data on which
d) Without full specification of the functions on which
View Answer
Answer: c
Explanation: The template classes can accept all types of data types. There is no need to specify the
data on which the class has to operate. Hence it gives us flexibility to code without worrying about
the type of data that might be used in the code.
7. What are the two specializations of I/O template classes in C++?
a) 16-bit character and wide characters
b) 8-bit character and wide characters
c) 32-bit character and locale characters
d) 64-bit characters and locale characters
View Answer
Answer: b
Explanation: The I/O specialization is made with wide character and 8-bit characters. Wide
characters are used to store the characters that might take more than 1 byte of space in memory or
any size that is different from the one that the machine is using.
8. Can typeid() function be used with the object of generic classes?
a) Yes, only if default type is given
b) Yes, always
c) No, generic data can’t be determined
d) No, never possible
View Answer
Answer: b
Explanation: The typeid() function can be used with the objects of generic classes. An instance of a
template class will take the type of data that is being used with it. Hence when typeid() function is
used, the data type would have already been defined and hence we can get desired result from
typeid() function.
9. The _____________ class is a specialization of a more general template class.
a) String
b) Integer
c) Digit
d) Math
View Answer
Answer: a
Explanation: The string class is more specialized. Since the string must be able to store any kind of
data that is given to the string. Hence it need maximum specialization.
10. How is function overloading different from template class?
a) Overloading is multiple function doing same operation, Template is multiple function doing
different operations
b) Overloading is single function doing different operations, Template is multiple function doing
different operations
c) Overloading is multiple function doing similar operation, Template is multiple function doing
identical operations
d) Overloading is multiple function doing same operation, Template is same function doing different
operations
View Answer
Answer: c
Explanation: The function overloading is multiple functions with similar or different functionality but
generic class functions perform the same task on given different types of data.
11. What if static members are declared inside template classes?
a) All instances will share the static variable
b) All instances will have their own static variable
c) All the instances will ignore the static variable
d) Program gives compile time error
View Answer
Answer: b
Explanation: The generic class have a special case with static members. Each instance will have its
own static member. The static members are not shared usually.
12. What is the output of following program?
template <typename T>
void test(const T&x)
{
static int count = 0;
cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; " count = " &lt;&lt; count &lt;&lt;
endl;
++count;
return;
}

void main()
{
test<int> (2);
test<int>(2);
test<double>(2.2);
}
a) x = 2 count = 0
x = 2.2 count = 0
x = 2.2 count = 0
b) x = 2 count = 0
x = 2 count = 0
x = 2.2 count = 0
c) x = 2 count = 0
x = 2 count = 1
x = 2.2 count = 0
d) x = 2 count = 0
x = 2 count = 1
x = 2.2 count = 2
View Answer
Answer: c
Explanation: For each new type, the class will have separate instance. Here two instances will be
created and hence counter for integer goes to 1. And for float value, the count remains 0 for the
output.
13. If template class is defined, is it necessary to use different types of data for each call?
a) No, not necessary
b) No, but at least two types must be there
c) Yes, to make proper use of template
d) Yes, for code efficiency
View Answer
Answer: a
Explanation: It is not necessary to use different type with each call to the generic function. Data may
be of same type with each call but still the function works. We don’t consider other properties like
efficiency with this concept because it is made generic to all data type, hence always works.
14. How many generic types can be given inside a single template class?
a) Only 1
b) Only 3
c) Only 7
d) As many as required
View Answer
Answer: d
Explanation: There is no restriction on the number of types to be used for making the class generic.
There can be any number of generic types with a single class. Hence giving flexibility to code with all
the data types.
15. Template classes must have at least one static member.
a) True
b) False
View Answer
Answer: b
Explanation: There is no mandatory condition to have static members inside template class. Not only
template, it is not mandatory to have static members anywhere. We can use them as required in the
code.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Class Use”.
1. Which among the following is the main characteristic of class?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Object creation
View Answer
Answer: b
Explanation: The classes are made to encapsulate the data and properties that are most similar and
can be grouped together inside a single class. This single class can represent all of those features
by creating its instances.
2. To group all the brands of cars, what should be used?
a) Class
b) Structure
c) Function
d) Object
View Answer
Answer: a
Explanation: A class can be used to group all the brands of cars. The Different brands may have
different properties but all will have some common properties like number of wheels and doors,
accessories etc. All of those properties can be grouped into a single class representing all the cars.
3. If a class have two data members and two functions to add those two numbers and to subtract
them, which among the following is most efficient if the programmer wants to implement
multiplication too?
a) Define a public function which multiplies two numbers
b) Define a public function that returns values of two data members
c) Define a private function which multiplies two numbers
d) Define a private function that returns values of two data members
View Answer
Answer: b
Explanation: The best choice would be to define a public member function that returns the values of
two data members of the class. This way we can implement any operation on those data members.
Also there won’t be any need to modify the program and to add new functions for each new
operation.
4. If a database have to be maintained using OOP, to store the details of each employee in a
company, which would be the best choice among the following?
a) Define a class to store details of each employee
b) Define a structure to store details of each employee
c) Define separate variable for each detail
d) Define a generic type to store string and number details
View Answer
Answer: a
Explanation: A single class can be defined that represents a single employee of a company. The
specific type of functions that can be applied to specific employees can be put into another class that
is derived from the existing class.
5. Which class represents the most abstracted information?
a) Nested
b) Derived
c) Enclosed
d) Base
View Answer
Answer: d
Explanation: The base classes are the most abstracted part of information. A base class having
many other derived classes would have a bigger overview of all the other derived classes. Hence the
base classes have the most abstract information.
6. Which among the following is an advantage of using classes over structures of C?
a) Functions are restricted
b) Functions can’t be defined
c) Fuctions can also be encapsulated
d) Functions can have more security
View Answer
Answer: c
Explanation: The functions are also made easy to be encapsulated inside a class. In structures, only
the data members were allowed to be encapsulated. Hence classes can represent an entity in a
better way.
7. Which among the follow is a feature of class?
a) Object orientation
b) Procedure orientation
c) Both object and procedure orientation
d) Neither object nor procedure orientation
View Answer
Answer: a
Explanation: Thee use of classes feature the object oriented programming. The OOP concept can
be implemented by using class and their objects. Procedures orientation is not feature of OOP.
8. Class is _____________ of an object.
a) Basic function definition
b) Detailed description with values
c) Blueprint
d) Set of constant values
View Answer
Answer: c
Explanation: The class is an overview for an object. It contains the basic details map of data that an
object will contain. An object is independent representation of class.
9. In which case the classes can be used to make more efficient program?
a) To define a function that is called frequently in a program
b) To structure data that is most similar
c) To group the most similar data and operations
d) To define a blueprint that shows memory location of data
View Answer
Answer: c
Explanation: The classes would be more suitable to use in case where we need to group the most
similar data and operations. The data can be represented as data members of class and operations
as member functions of class. This is indirectly encapsulation feature.
10. What is the use of inbuilt classes?
a) Provide predefined data
b) Provede predefined functions
c) Provide predefined data and functions
d) Provide predeclared data to be overridden
View Answer
Answer: c
Explanation: The data that is constant or is always the same initially for use can be provided by
some inbuilt classes. The functions that are mostly used are also provided by the inbuilt classes. The
data and functions can be used by including the corrosponding header file or library.
11.Which feature is exhibited by the inbuilt classes?
a) Code reusability
b) Code effeciency
c) Code readability
d) Code reusability, effeciency and readability
View Answer
Answer: d
Explanation: The code is reusable as the functions which are already written, can be used anytime
required. The code becomes easier to read. Also, the code is efficient as there is no need to assign
any external code.
12. Why do we use user defined classes?
a) To desined a user intended code
b) To model real world objects
c) To desing the interfaces
d) To model the functions
View Answer
Answer: b
Explanation: The primitive classes are not sufficient for the programming complex algorithms. Some
user defined classes are required to represent a real world object and to define a blueprint of what
the class should actually contain. The user defined classes are as per the requirements and need of
user.
13. Why do classes use accessor methods?
a) To make public data accessible to client
b) To make public data private to client
c) To make private data public for whole program
d) To make private data accessible to the client
View Answer
Answer: d
Explanation: The private data of a class is usually not accessible. But the data can be accessed by
the user using accessor functions. These functions allows the user to get the data stored as private
in a class.
14. Why do classes use mutator methods?
a) Allows client to modify the program
b) Allows client to modify/write the private members
c) Allows servers to access all the private data
d) Allows servers to access only protected members
View Answer
Answer: b
Explanation: The client can have rights to access a file and write something to it. This is mandatory
to keep the private data updated. Also it is an advantage over the use of hidden class members.
15. Which among the following is the most abstract form of class?
a) Cars
b) BMW cars
c) Big cars
d) Small cars
View Answer
Answer: a
Explanation: The most abstract class is class Cars. The class Cars is most general form of all other
cars. If it is a brand of car, it comes under car. If it is type of car then alsoo it comes under Cars.

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Base Class”.
1. Which is most appropriate definition of a base class?
a) It is parent of any of its derived class
b) It is child of one of the parent class
c) It is most basic class of whole program
d) It is class with maximum number of members
View Answer
Answer: a
Explanation: A class which is parent of another class, or from which other classes can be derived, is
known as a base class. It is mandatory that a class must have at least one derived class to be called
as a base class.
2. A base class is also known as _____________ class.
a) Basic
b) Inherited
c) Super
d) Sub
View Answer
Answer: c
Explanation: A class which is being derived by other classes, is called as super class. This concept
is clearly used in java as we call the functions of a base class by using the keyword super as
required.
3. An abstract class is always a __________ class.
a) Base
b) Derived
c) Template
d) Nested
View Answer
Answer: a
Explanation: Every abstract class is a base class. It must be so, because the functions which are not
defined inside the abstract class, must be defined in the derived classes. Hence it becomes a base
class.
4. How many base classes can a single class inherit in java?
a) 1
b) 2
c) 3
d) As many as required
View Answer
Answer: a
Explanation: In java, multiple inheritance is not supported, which leads to the fact that a class can
have only 1 parent class if inheritance is used. Only if interfaces are used then the class can
implement more than one base class.
5. How to make a derived class a base class?
a) Change name of the class
b) Use keyword base
c) Make a class derive from it
d) Can’t be done
View Answer
Answer: c
Explanation: Making another class derive from it will make that class as base class. It is not
necessary that we have to write a different code for it. If at least one class derives that class, it
becomes the base class for the new class.
6. If a base class is being derived by two other classes, which inheritance will that be called?
a) Single
b) Multiple
c) Multi-level
d) Hierarchical
View Answer
Answer: d
Explanation: When more than one classes are being derived from a single parent class, the
inheritance is known as hierarchical inheritance. This is usually useful when the base class is higher
abstraction of its derived classes.
7. Which among the following must be in a base class?
a) Data members
b) Member functions
c) Access specifiers
d) Nothing
View Answer
Answer: d
Explanation: Even a class which doesn’t have any members can be a base class. It is not mandatory
to have any member or attribute in base class.
8. Which type of members can’t be accessed in derived classes of a base class?
a) Protected
b) Private
c) Public
d) All can be accessed
View Answer
Answer: b
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.
9. If a class is enclosing more than one class, than it can be called as base class of those classes.
a) True
b) False
View Answer
Answer: b
Explanation: When a class have more than one nested classes, it is known as enclosing class. It
can’t be called as parent or base class since there is no inheritance involved.
10. Base class have ________________ of abstraction.
a) Higher degree
b) Lower degree
c) Intermediate
d) Minimum degree
View Answer
Answer: b
Explanation: A base class will have lesser information as compared to those of derived classes.
Since derived classes inherit the base class properties and then add on their own features, they
elaborate more hence have lower degree of abstraction.
11. Always the base class constructors are called ___________ constructor of derived class.
a) Before
b) After
c) Along
d) According to priority of
View Answer
Answer: a
Explanation: When the base class object is created, its constructor will be called for sure. But if
derived class constructor is called, first base class constructor is called and then derived class
constructor is taken into consideration.
12. Can we call methods of base class using constructor of the derived class?
a) Yes, always
b) Yes, but not always
c) No, never
d) No, but we can call in some cases
View Answer
Answer: a
Explanation: If the function is defined in the base class, it can always be called from the constructor
of its derived class. Since the constructors are not private, they can be accessed in derived class
even if those are protected.
13. If a base class is inherited from another class and then one class derives it, which inheritance is
shown?
a) Multiple
b) Single
c) Hierarchical
d) Multi-level
View Answer
Answer: d
Explanation: If a base class is inherited from another class, single inheritance is shown. But when
one more class inherits the derived class, this becomes a multi-level inheritance.
14. How many base classes can a single derived class have in C++?
a) 1
b) 2
c) 3
d) As many as required
View Answer
Answer: d
Explanation: This is because C++ allows the multiple inheritance. A derived class can have more
than one base class and hence can derive all of their features.
15. If a base class is added with few new members, its subclass must also be modified. (True/False)
a) True
b) False
View Answer
Answer: b
Explanation: The base class can be added with new members without affecting the sub classes.
This is because the sub classes may get some more features inherited but it won’t use them. But the
base class will be able to use the new members as would be required.

Potrebbero piacerti anche