Вы находитесь на странице: 1из 94

Java oops 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

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.
advertisement

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.
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 subclass 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

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 subclasses 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.
advertisement

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.
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.
advertisement

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.
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.
advertisement

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.
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 accidentally.
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 accidentally. 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:
advertisement

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
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

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 and 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 another, 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.
advertisement

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.
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

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 and 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 another, 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.
advertisement

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.
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 value 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.
advertisement

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.
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.
advertisement

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 initializations
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.
1. Copy constructor is a constructor which ________________
a) Creates an object by copying values from any other object of same class
b) Creates an object by copying values from first object created for that class
c) Creates an object by copying values from another object of another class
d) Creates an object by initializing it with another previously created object of same class
View Answer
Answer: d
Explanation: The object that has to be copied to new object must be previously created. The new
object gets initialized with the same values as that of the object mentioned for being copied. The
exact copy is made with values.
2. The copy constructor can be used to:
a) Initialize one object from another object of same type
b) Initialize one object from another object of different type
c) Initialize more than one object from another object of same type at a time
d) Initialize all the objects of a class to another object of another class
View Answer
Answer: a
Explanation: The copy constructor has the most basic function to initialize the members of an object
with same values as that of some previously created object. The object must be of same class.
3. If two classes have exactly same data members and member function and only they differ by
class name. Can copy constructor be used to initialize one class object with another class object?
a) Yes, possible
b) Yes, because the members are same
c) No, not possible
d) No, but possible if constructor is also same
View Answer
Answer: c
Explanation: The restriction for copy constructor is that it must be used with the object of same class.
Even if the classes are exactly same the constructor won’t be able to access all the members of
another class. Hence we can’t use object of another class for initialization.
4. The copy constructors can be used to ________
a) Copy an object so that it can be passed to a class
b) Copy an object so that it can be passed to a function
c) Copy an object so that it can be passed to another primitive type variable
d) Copy an object for type casting
View Answer
Answer: b
Explanation: When an object is passed to a function, actually its copy is made in the function. To
copy the values, copy constructor is used. Hence the object being passed and object being used in
function are different.
5. Which returning an object, we can use ____________
a) Default constructor
b) Zero argument constructor
c) Parameterized constructor
d) Copy constructor
View Answer
Answer: d
Explanation: While returning an object we can use the copy constructor. When we assign the return
value to another object of same class then this copy constructor will be used. And all the members
will be assigned the same values as that of the object being returned.
6. If programmer doesn’t define any copy constructor then _____________
a) Compiler provides an implicit copy constructor
b) Compiler gives an error
c) The objects can’t be assigned with another objects
d) The program gives run time error if copying is used
View Answer
Answer: a
Explanation: The compiler provides an implicit copy constructor. It is not mandatory to always create
an explicit copy constructor. The values are copied using implicit constructor only.
7. If a class implements some dynamic memory allocations and pointers then _____________
a) Copy constructor must be defined
b) Copy constructor must not be defined
c) Copy constructor can’t be defined
d) Copy constructor will not be used
View Answer
Answer: a
Explanation: In the case where dynamic memory allocation is used, the copy constructor definition
must be given. The implicit copy constructor is not capable of manipulating the dynamic memory and
pointers. Explicit definition allows to manipulate the data as required.
8. What is the syntax of copy constructor?
a) classname (classname &obj){ /*constructor definition*/ }
b) classname (cont classname obj){ /*constructor definition*/ }
c) classname (cont classname &obj){ /*constructor definition*/ }
d) classname (cont &obj){ /*constructor definition*/ }
View Answer

9. Object being passed to a copy constructor ___________


a) Must be passed by reference
b) Must be passed by value
c) Must be passed with integer type
d) Must not be mentioned in parameter list
View Answer
Answer: a
Explanation: This is mandatory to pass the object by reference. Otherwise the object will try to create
another object to copy its values, in turn a constructor will be called, and this will keep on calling
itself. This will cause the compiler to give out of memory error.
10. Out of memory error is given when the object _____________ to the copy constructor.
a) Is passed with & symbol
b) Is passed by reference
c) Is passed as
d) Is not passed by reference
View Answer
Answer: d
Explanation: All the options given, directly or indirectly indicate that the object is being passed by
reference. And if object is not passed by reference then the out of memory error is produced. Due to
infinite constructor call of itself.
11. Copy constructor will be called whenever the compiler __________
a) Generates implicit code
b) Generates member function calls
c) Generates temporary object
d) Generates object operations
View Answer
Answer: c
Explanation: Whenever the compiler creates a temporary object, copy constructor is used to copy
the values from existing object to the temporary object.
12. The deep copy is possible only with the help of __________
a) Implicit copy constructor
b) User defined copy constructor
c) Parameterized constructor
d) Default constructor
View Answer
Answer: b
Explanation: While using explicit copy constructor, the pointers of copied object point to the intended
memory location. This is assured since the programmers themselves manipulate the addresses.
advertisement

13. Can a copy constructor be made private?


a) Yes, always
b) Yes, if no other constructor is defined
c) No, never
d) No, private members can’t be accessed
View Answer
Answer: a
Explanation: The copy constructor can be defined private. If we make it private then the objects of
the class can’t be copied. It can be used when a class used dynamic memory allocation.
14. The arguments to a copy constructor _____________
a) Must be const
b) Must not be cosnt
c) Must be integer type
d) Must be static
View Answer
Answer: a
Explanation: The object should not be modified in the copy constructor. Because the object itself is
being copied. When the object is returned from a function, the object must be a constant otherwise
the compiler creates a temporary object which can die anytime.
15. Copy constructors are overloaded constructors.
a) True
b) False
View Answer
Answer: a
Explanation: The copy constructors are always overloaded constructors. They has to be. All the
classes have a default constructor and other constructors are basically overloaded constructors.
1. Which among the following best describes constructor overloading?
a) Defining one constructor in each class of a program
b) Defining more than one constructor in single class
c) Defining more than one constructor in single class with different signature
d) Defining destructor with each constructor
View Answer
Answer: c
Explanation: If more than one constructors are defined in a class with same signature, then that
results in error. The signatures must be different. So that the constructors can be differentiated.
2. Can constructors be overloaded in derived class?
a) Yes, always
b) Yes, if derived class has no constructor
c) No, programmer can’t do it
d) No, never
View Answer
Answer: d
Explanation: The constructor must be having the same name as that of a class. Hence a constructor
of one class can’t even be defined in another class. Since the constructors can’t be defined in
derived class, it can’t be overloaded too, in derived class.
3. Does constructor overloading include different return types for constructors to be overloaded?
a) Yes, if return types are different, signature becomes different
b) Yes, because return types can differentiate two functions
c) No, return type can’t differentiate two functions
d) No, constructors doesn’t have any return type
View Answer
Answer: d
Explanation: The constructors doesn’t have any return type. When we can’t have return type of a
constructor, overloading based on the return type is not possible. Hence only parameters can be
different.
4. Which among the following is possible way to overload constructor?
a) Define default constructor, 1 parameter constructor and 2 parameter constructor
b) Define default constructor, zero argument constructor and 1 parameter constructor
c) Define default constructor, and 2 other parameterized constructors with same signature
d) Define 2 default constructors
View Answer
Answer: a
Explanation: All the constructors defined in a class must have different signature in order to be
overloaded. Here one default and other parameterized constructors are used, wherein one is of only
one parameter and other accepts two. Hence overloading is possible.
5. Which constructor will be called from the object created in the code below?
class A
{
int i;
A()
{
i=0; cout&lt;&lt;i;
}
A(int x=0)
{
i=x; cout&lt;&lt;I;
}
};
A obj1;

a) Default constructor
b) Parameterized constructor
c) Compile time error
d) Run time error
View Answer
Answer: c
Explanation: When a default constructor is defined and another constructor with 1 default value
argument is defined, creating object without parameter will create ambiguity for the compiler. The
compiler won’t be able to decide which constructor should be called, hence compile time error.
6. Which among the following is false for a constructor?
a) Constructors doesn’t have a return value
b) Constructors are always user defined
c) Constructors are overloaded with different signature
d) Constructors may or may not have any arguments being accepted
View Answer
Answer: b
Explanation: The constructors are not always user defined. The construct will be provided implicitly
from the compiler if the used doesn’t defined any constructor. The implicit constructor makes all the
string values null and allocates memory space for each data member.
7. When is the constructor called for an object?
a) As soon as overloading is required
b) As soon as class is derived
c) As soon as class is created
d) As soon as object is created
View Answer
Answer: d
Explanation: The constructor is called as soon as the object is created. The overloading comes into
picture as to identify which constructor have to be called depending on arguments passed in creation
of object.
8. Which among the following function can be used to call default constructor implicitly in java?
a) this()
b) that()
c) super()
d) sub()
View Answer
Answer: a
Explanation: The function this() can be used to call the default constructor from inside any other
constructor. This helps to further reuse the code and not to write the redundant data in all the
constructors.
9. Why do we use constructor overloading?
a) To use different types of constructors
b) Because it’s a feature provided
c) To initialize the object in different ways
d) To differentiate one constructor from another
View Answer
Answer: c
Explanation: The constructors are overloaded to initialize the objects of a class in different ways.
This allows us to initialize the object with either default values or used given values. If data members
are not initialized then program may give unexpected results.
10. If programmer have defined parameterized constructor only, then __________________
a) Default constructor will not be created by the compiler implicitly
b) Default constructor will be created by the compiler implicitly
c) Default constructor will not be created but called at runtime
d) Compile time error
View Answer
Answer: a
Explanation: When the programmer doesn’t specify any default constructor and only defines some
parameterized constructor. The compiler doesn’t provide any default constructor implicitly. This is
because it is assumed that the programmer will create the objects only with constructors.
advertisement

11. Which among the following is not valid in java?


a) Constructor overloading
b) Recursive constructor call
c) Default value constructors
d) String argument constructor
View Answer
Answer: b
Explanation: Java doesn’t provide the feature to recursively call the constructor. This is to eliminate
the out of memory error in some cases that arises unexpectedly. That is an predefined condition for
constructors in java.
12. Which constructor will be called from the object obj2 in the following program?
class A
{
int i;
A()
{
i=0;
}
A(int x)
{
i=x+1;
}
A(int y, int x)
{
i=x+y;
}
};
A obj1(10);
A obj2(10,20);
A obj3;
a) A(int x)
b) A(int y)
c) A(int y, int x)
d) A(int y; int x)
View Answer
Answer: c
Explanation: The two argument constructor will be called as we are passing 2 arguments to the
object while creation. The arguments will be passed together and hence compiler resolves that two
argument constructor have to be called.
13. What is we only create an object but don’t call any constructor for it in java?
a) Implicit constructor will be called
b) Object is initialized to some null values
c) Object is not created
d) Object is created but points to null
View Answer
Answer: d
Explanation: The object becomes a reference object which can be initialized will another object.
Then this object will indirectly become another name of the object being assigned. If not assigned, it
simply points to null address.
14. Which among the following is false?
a) Constructor can’t be overloaded in Kotlin
b) Constructors can’t be called recursively in java
c) Constructors can be overloaded in C++
d) Constructors overloading depends on different signatures
View Answer
Answer: a
Explanation: Kotlin language allows constructor overloading. This is a basic feature for the
constructors. The constructor overloading allows the object to be initialized according to the user.
15. Which is correct syntax?
a) classname objectname= new() integer;
b) classname objectname= new classname;
c) classname objectname= new classname();
d) classname objectname= new() classname();
View Answer
Answer: c
Explanation: The syntax for object creating in java with calling a constructor for is it is as in option c.
The syntax must contain the classname followed by the object name. The keyword new must be
used and then the constructor call with or without the parameters as required
1. Which among the following best describes the constructors?
a) A function which is called whenever an object is referenced
b) A function which is called whenever an object is created to initialize the members
c) A function which is called whenever an object is assigned to copy the values
d) A function which is called whenever an object is to be given values for members
View Answer
Answer: b
Explanation: The constructors are special type of functions which are called whenever an object is
created. This is to initialize the data members of the class. The constructor allocates memory space
for all the data members.
2. Which among the following best describes destructor?
a) A function which is called just before the objects are destroyed
b) A function which is called after each reference to the object
c) A function which is called after termination of the program
d) A function which is called before calling any member function
View Answer
Answer: a
Explanation: The Destructors are special functions which are called just before an object is
destroyed. This functions is responsible to free all the allocated resources to the object. Objects are
destroyed whenever those go out of scope.
3. Which among the following represents correct constructor?
a) ()classname
b) ~classname()
c) –classname()
d) classname()
View Answer
Answer: d
Explanation: The constructors must contain only the class name. The class name is followed by the
blank parenthesis or we can have parameters if some values are to be passed.
4. Which among the following is correct syntax for the destructors?
a) classname()
b) ()classname
c) ~classname()
d) -classname()
View Answer
Answer: c
Explanation: The destructor must have same name as that of the corresponding class. The class
name should be preceded by the tilde symbol (~).
5. Which among the following is true?
a) First the constructor of parent classes are called in sequence of inheritance
b) First the constructor of child classes are called in the sequence of inheritance
c) First constructor called is of the object being created
d) Constructors are called randomly
View Answer
Answer: a
Explanation: First the constructor of parent class are called. The order in which the parent class
constructors are called is same in the sequence of inheritance used.
6. What is the sequence of destructors call?
a) Same order as that of the constructors call
b) Random order
c) According to the priority
d) Revere of the order of constructor call
View Answer
Answer: d
Explanation: The destructors are called in the reverse order as that of the constructors being called.
This is done to ensure that all the resources are released in sequence. That is, the derived class
destructors will be called first.
7. The destructors _____________________
a) Can have maximum one argument
b) Can’t have any argument
c) Can have more than one argument
d) Can’t have more than 3 arguments
View Answer
Answer: b
Explanation: The destructors doesn’t have any arguments. The destructors have to be called
implicitly whenever an object goes out of scope. The user can’t pass argument to the implicit call.
8. Destructor calls ________________ (C++)
a) Are only implicit
b) Are only explicit
c) Can be implicit or explicit
d) Are made at end of program only
View Answer
Answer: c
Explanation: The destructors are usually called implicitly whenever an object goes out of scope. The
destructors can also be called explicitly if required. The call must be made, implicitly or explicitly.
9. Number of destructors called are
a) Always equal to number of constructors called
b) Always less than the number of constructors called
c) Always greater than the number of constructors called
d) Always less than or equal to number of constructors
View Answer
Answer: a
Explanation: Destructor will be called only to free the resources allocated for an object. The
resources are allocated only the constructor for an object is called.
10. For explicit call _________________
a) The destructor must be private
b) The destructor must be public
c) The destructor must be protected
d) The destructor must be defined outside the class
View Answer
Answer: b
Explanation: The destructor must be public for explicit calls. If it is made private or protected then it
won’t be accessible outside the class. There is no restriction of definition the destructor outside the
class.
11. If a class have 4 constructors then it must have 4 destructors also.
a) True
b) False
View Answer
Answer: b
Explanation: Even if the class have 4 constructors, only one would be used. And only one destructor
is allowed.
12. Which among the following is true for destructors?
a) Destructors can be overloaded
b) Destructors can be define more than one time
c) Destructors can’t be overloaded
d) Destructors are overloaded in derived classes
View Answer
Answer: c
Explanation: The destructors can never be overloaded. The destructors doesn’t have arguments.
And to get overloaded, they must have different signature. This is not possible if arguments are not
allowed.
advertisement
13. The constructor _____________
a) Have a return type
b) May have a return type
c) Of derived classes have return type
d) Doesn’t have a return type
View Answer
Answer: d
Explanation: The constructors doesn’t have any return type. The constructors are intended to
allocate the resources for the object. Memory spaces are to be finalized.
14. The destructors ____________
a) Have a return type
b) May have a return type
c) Of derived classes have return type
d) Doesn’t have a return type
View Answer
Answer: d
Explanation: The destructors are intended to free the memory space. And all the resources that were
allocated for the object. The return value is not supported since only memory have to be made free.
15. The destructor can be called before the constructor if required. (True/False)
a) True
b) False
View Answer
Answer: b
Explanation: The destructors can be called only after the constructor calls. It is not a mandatory rule
but the deletion can only take place if there is something created using the constructor.
1. Which among the following describes a destructor?
a) A special function that is called to free the resources, acquired by the object
b) A special function that is called to delete the class
c) A special function that is called anytime to delete an object
d) A special function that is called to delete all the objects of a class
View Answer
Answer: a
Explanation: It is used to free the resources that the object might had used in its lifespan. The
destructors are called implicitly whenever an object’s life ends.
2. When a destructor is called?
a) After the end of object life
b) Anytime in between object’s lifespan
c) At end of whole program
d) Just before the end of object life
View Answer
Answer: d
Explanation: The destructor is called just before the object go out of scope or just before its life ends.
This is done to ensure that all the resources reserved for the object are used and at last, are made
free for others.
3. Which among the following is correct for abstract class destructors?
a) It doesn’t have destructors
b) It has destructors
c) It may or may not have destructors
d) It contains an implicit destructor
View Answer
Answer: a
Explanation: It doesn’t have destructors. Since an abstract class don’t have constructors, and hence
can’t have instances. Having this case, the abstract classes don’t have destructors too, because that
would be of no use here.
4. If in multiple inheritance, class C inherits class B, and Class B inherits class A. In which sequence
are their destructors called, if an object of class C was declared?
a) ~C() then ~B() then ~A()
b) ~B() then ~C() then ~A()
c) ~A() then ~B() then ~C()
d) ~C() then ~A() then ~B()
View Answer
Answer: a
Explanation: The destructors are always called in the reverse order of how the constructors were
called. Here class A constructor would have been created first if Class C object is declared. Hence
class A destructor is called at last.
5. Choose the correct sequence of destructors being called for the following code:
class A{ };
class B{ };
class C: public A, public B{ };
a) ~A(), ~B(), ~C()
b) ~B(), ~C(), ~A()
c) ~A(), ~C(), ~B()
d) ~C(), ~B(), ~A()
View Answer
Answer: d
Explanation: In multiple inheritance, the constructors are called in the sequence of how they are
written in inheritance sequence. And the destructors will be called in the reverse order. This can be
cross verified just by printing a message from each destructor defined in classes.
6. When is the destructor of a global object called?
a) Just before end of program
b) Just after end of program
c) With the end of program
d) Anytime when object is not needed
View Answer
Answer: a
Explanation: This is because the lifespan of global object is from start of the program, till the end of
the program. And hence program end is the end of global object too. Just before the end of program,
the destructor will be called to free the acquired resources by the objects.
7. How the constructors and destructors can be differentiated?
a) Destructor have a return type but constructor doesn’t
b) Destructors can’t be defined by the programmer, but constructors can be defined
c) Destructors are preceded with a tilde (~) symbol, and constructor doesn’t
d) Destructors are same as constructors in syntax
View Answer
Answer: c
Explanation: The destructors are preceded with the tilde (~) symbol. The name is same as that of the
class. These also doesn’t have any return type.
8. Destructors doesn’t accept parameters.
a) True
b) False
View Answer
Answer: a
Explanation: The destructors doesn’t accept the arguments. Those are just used to free up the
resources.
9. Destructors can be ________
a) Abstract type
b) Virtual
c) Void
d) Any type depending on situation
View Answer
Answer: b
Explanation: The destructors can be virtual. It is actually advised to keep the destructors virtual
always. This is done to suppress the problems that may arise if inheritance is involved.
10. Global destructors execute in ___________ order after main function is terminated
a) Sequential
b) Random
c) Reverse
d) Depending on priority
View Answer
Answer: c
Explanation: The destructors are always called in reverse order no matter which destructor it is. This
is done to ensure that all the resources are able to get free. And no resource is kept busy.
11. When is it advised to have user defined destructor?
a) When class contains some pointer to memory allocated in class
b) When a class contains static variables
c) When a class contains static functions
d) When a class is inheriting another class only
View Answer
Answer: a
Explanation: This is always advised to have user defined destructor when pointers are involved in
class. This is usually done to ensure that the memory, that was allocated dynamically, gets free after
use and doesn’t cause memory leak.
12. Which among the following is correct for destructors concept?
a) Destructors can be overloaded
b) Destructors can have only one parameter at maximum
c) Destructors are always called after object goes out of scope
d) There can be only one destructor in a class
View Answer
Answer: d
Explanation: This is so because the destructors can’t be overloaded. And the destructor must have
the same name as that of class with a tilde symbol preceding the name of destructor. Hence there
can be only one destructor in a class. Since more than one function with same name and signature
can’t be present in same scope.
advertisement

13. Which class destructor will be called first, when following code go out of scope?
class A{ };
class B{ };
class C: public B{ };
A a;
B b;
C c;

a) ~A()
b) ~B()
c) ~C()
d) ~B() and ~C()
View Answer
Answer: c
Explanation: The constructor that would have created at last, its destructor will be called first when
the code goes out of scope. This will help the program to manage the resources more efficiently.
14. When an object is passed to a function, its copy is made in the function and then:
a) The destructor of the copy is called when function is returned
b) The destructor is never called in this case
c) The destructor is called but it is always implicit
d) The destructor must be user defined
View Answer
Answer: a
Explanation: When an object is passed to a function, its copy is made in the function. This copy acts
as a real object till the function is live. When the function is returned, the copy’s destructor is called
to free the resources held by it.
15. What happens when an object is passed by reference?
a) Destructor is not called
b) Destructor is called at end of function
c) Destructor is called when function is out of scope
d) Destructor is called when called explicitly
View Answer
Answer: a
Explanation: The destructor is never called in this situation. The concept is that when an object is
passed by reference to the function, the constructor is not called, but only the main object will be
used. Hence no destructor will be called at end of function.
. Which is the pointer which denotes the object calling the member function?
a) Variable pointer
b) This pointer
c) Null pointer
d) Zero pointer
View Answer
Answer: b
Explanation: The pointer which denotes the object calling the member function is known as this
pointer. The this pointer is usually used when there are members in the function with same name as
those of the class members.
2. Which among the following is true?
a) this pointer is passed implicitly when member functions are called
b) this pointer is passed explicitly when member functions are called
c) this pointer is passed with help of pointer member functions are called
d) this pointer is passed with help of void pointer member functions are called
View Answer
Answer: a
Explanation: When an object calls some member function, it implicitly passes itself as an argument.
This allows the compiler to know which member should be used for the purposes. This also allows to
reduce the ambiguity among the variable and data member names.
3. The this pointer is accessible __________________
a) Within all the member functions of the class
b) Only within functions returning void
c) Only within non-static functions
d) Within the member functions with zero arguments
View Answer
Answer: c
Explanation: The this pointer is available only within the non-static member functions of a class. If
the member function is static, it will be common to all the objects and hence a single object can’t
refer to those functions independently.
4. An object’s this pointer _____________________
a) Isn’t part of class
b) Isn’t part of program
c) Isn’t part of compiler
d) Isn’t part of object itself
View Answer
Answer: d
Explanation: The object’s this pointer being called are not part of the object itself. This can be cross
verified by checking that it doesn’t take up any space for the data to be stored or pointed.
5. The result of sizeof() function __________________
a) Includes space reserved for this pointer
b) Includes space taken up by the address pointer by this pointer
c) Doesn’t include the space taken by this pointer
d) Doesn’t include space for any data member
View Answer
Answer: c
Explanation: The space taken by this pointer is not reflected in by the sizeof() operator. This is
because object’s this pointer is not part of object itself. This is a cross verification for the concept
stating that this pointer doesn’t take any space in the object.
6. Whenever non-static member functions are called _______________
a) Address of the object is passed implicitly as an argument
b) Address of the object is passed explicitly as an argument
c) Address is specified globally so that the address is not used again
d) Address is specified as return type of the function
View Answer
Answer: a
Explanation: The address is passed implicitly as an argument to the function. This doesn’t have to
be passed explicitly. The address is passed, of the object which is calling the non-static member
function.
7. Which is the correct interpretation of the member function call from an object,
object.function(parameter);
a) object.function(&this, parameter)
b) object(&function,parameter)
c) function(&object,&parameter)
d) function(&object,parameter)
View Answer
Answer: d
Explanation: The function name is specified first and then the parameter lists. The parameter list is
included with the object name along with & symbol. This denotes that the address of the object is
being passed as an argument.
8. The address of the object _________________
a) Can’t be accessed from inside the function
b) Can’t be accessed in the program
c) Is available inside the member function using this pointer
d) Can be accessed using the object name inside the member function
View Answer
Answer: c
Explanation: The address of the object with respect to which the member functions are being called,
are stored in this pointer. This pointer is hence used whenever there are members with same name
as those of the variables inside the function.
9. Which among the following is true?
a) This pointer can be used to guard against any kind of reference
b) This pointer can be used to guard against self-reference
c) This pointer can be used to guard from other pointers
d) This pointer can be used to guard from parameter referencing
View Answer
Answer: b
Explanation: The this pointer can be used to guard itself whenever self-reference is used. This
allows accidental address access. And accidental modification of data.
10. Which syntax doesn’t execute/is false when executed?
a) if(&object != this)
b) if(&function !=object)
c) this.if(!this)
d) this.function(!this)
View Answer
Answer: a
Explanation: The condition becomes false when executed and hence doesn’t executes. This is the
case where this pointer can guard itself from the self-reference. Here if the address of the object
doesn’t match with this pointer that means the object doesn’t refer itself.
11. The this pointers _____________________
a) Are modifiable
b) Can be assigned any value
c) Are made variables
d) Are non-modifiable
View Answer
Answer: d
Explanation: The this pointer is non modifiable. This is because the address of any object remains
constant throughout its life time. Hence the address must not be changed otherwise wrong members
of invalid addresses might get accessed.
12. Earlier implementations of C++ ___________________
a) Never allowed assignment to this pointer
b) Allowed no assignment to this pointer
c) Allowed assignments to this pointer
d) Never allowed assignment to any pointer
View Answer
Answer: c
Explanation: The earlier, most initial versions of C++ used to allow assignments to this pointers. That
used to allow modifications of this pointer. Later that feature got disabled.
advertisement

13. This pointer can be used directly to ___________


a) To manipulate self-referential data structures
b) To manipulate any reference to pointers to member functions
c) To manipulate class references
d) To manipulate and disable any use of pointers
View Answer
Answer: a
Explanation: This is a feature provided, that can be used directly. The manipulation of self-referential
data structures is just an application of this feature. Other conditions fails as this pointer doesn’t deal
with those things.
14. Which among the following is/are type(s) of this pointer?
a) const
b) volatile
c) const or volatile
d) int
View Answer
Answer: c
Explanation: The this pointer can be declared const or volatile. This depends on need of program
and type of code. This is just an additional feature.
15. Which is the correct syntax for declaring type of this in a member function?
a) classType [cv-qualifier-list] *const this;
b) classType const[cv-qualifier-list] *this;
c) [cv-qualifier-list]*const classType this;
d) [cv-qualifier-list] classType *const this;
View Answer
Answer: d
Explanation: The syntax contains the cv-qualifier-list that can be determined from the member
function declaratory that can be either const or volatile or can be made both. Hence we write it as
list. classType denotes the name of class to mention to which class does the object belong to. And
*const this denotes that the this pointer is having a constant value.
1. Which among the following best describes the Inheritance?
a) Copying the code already written
b) Using the code already written once
c) Using already defined functions in programming language
d) Using the data and functions into derived segment
View Answer
Answer: d
Explanation: It can only be indicated by using the data and functions that we use in derived class,
being provided by parent class. Copying code is nowhere similar to this concept, also using the code
already written is same as copying. Using already defined functions is not inheritance as we are not
adding any of our own features.
2. How many basic types of inheritance are provided as OOP feature?
a) 4
b) 3
c) 2
d) 1
View Answer
Answer: a
Explanation: There are basically 4 types of inheritance provided in OOP, namely, single
level,multilevel, multiple and hierarchical inheritance. We can add one more type as Hybrid
inheritance but that is actually the combination any types of inheritance from the 4 basic ones.
3. Which among the following best defines single level inheritance?
a) A class inheriting a derived class
b) A class inheriting a base class
c) A class inheriting a nested class
d) A class which gets inherited by 2 classes
View Answer
Answer: b
Explanation: A class inheriting a base class defines single level inheritance. Inheriting an already
derived class makes it multilevel inheritance. And if base class is inherited by 2 other classes, it is
multiple inheritance.
4. Which among the following is correct for multiple inheritance?
a) class student{public: int marks;}s; class stream{int total;}; class topper:public student, public
stream{ };
b) class student{int marks;}; class stream{ }; class topper: public student{ };
c) class student{int marks;}; class stream:public student{ };
d) class student{ }; class stream{ }; class topper{ };
View Answer
Answer: a
Explanation: Class topper is getting derived from 2 other classes and hence it is multiple inheritance.
Topper inherits class stream and class student publicly and hence can use its features. If only few
classes are defined, there we are not even using inheritance (as in option d).
5. Which programming language doesn’t support multiple inheritance?
a) C++ and Java
b) C and C++
c) Java and SmallTalk
d) Java
View Answer
Answer: d
Explanation:Java doesn’t support multiple inheritance. But that feature can be implemented by using
the interfaces concept. Multiple inheritance is not supported because of diamond problem and
similar issues.
6. Which among the following is correct for hierarchical inheritance?
a) Two base classes can be used to be derived into one single class
b) Two or more classes can be derived into one class
c) One base class can be derived into other two derived classes or more
d) One base class can be derived into only 2 classes
View Answer
Answer: c
Explanation: One base class can be derived into other two derived classes or more. If only one class
gets derived by only 2 other classes, it is also hierarchical inheritance, but it is not a mandatory
condition, because any number of derived classes can be there.
7. Which is the correct syntax of inheritance?
a) class derived_classname : base_classname{ /*define class body*/ };
b) class base_classname : derived_classname{ /*define class body*/ };
c) class derived_classname : access base_classname{ /*define class body*/ };
d) class base_classname :access derived_classname{ /*define class body*/ };
View Answer
Answer: c
Explanation: Firstly, keyword class should come, followed by the derived class name. Colon is must
followed by access in which base class has to be derived, followed by the base class name. And
finally the body of class. Semicolon after the body is also must.
8. Which type of inheritance leads to diamond problem?
a) Single level
b) Multi-level
c) Multiple
d) Hierarchical
View Answer
Answer: c
Explanation: When 2 or more classes inherit the same class using multiple inheritance and then one
more class inherits those two base classes, we get a diamond like structure. Here, ambiguity arises
when same function gets derived into 2 base classes and finally to 3rd level class, because same
name functions are being inherited.
9. Which access type data gets derived as private member in derived class:
a) Private
b) Public
c) Protected
d) Protected and Private
View Answer
Answer: a
Explanation: It is a rule, that when a derived class inherits the base class in private access mode, all
the members of base class gets derived as private members of the derived class.
10. If a base class is inherited in protected access mode then which among the following is true?
a) Public and Protected members of base class becomes protected members of derived class
b) Only protected members become protected members of derived class
c) Private, Protected and Public all members of base, become private of derived class
d) Only private members of base, become private of derived class
View Answer
Answer: a
Explanation: As the programming language rules apply, all the public and protected members of
base class becomes protected members of derived class in protected access mode. It can’t be
changed because it would hinder the security of data and may add vulnerability in program.
11. Members which are not intended to be inherited are declared as:
a) Public members
b) Protected members
c) Private members
d) Private or Protected members
View Answer
Answer: c
Explanation: Private access specifier is the most secure access mode. It doesn’t allow members to
be inherited. Even Private inheritance can only inherit protected and public members.
12. While inheriting a class, if no access mode is specified, then which among the following is true?
(in C++)
a) It gets inherited publicly by default
b) It gets inherited protected by default
c) It gets inherited privately by default
d) It is not possible
View Answer
Answer: c
Explanation: If the access mode is not specified during inheritance, the class is inherited privately by
default. This is to ensure the security of data and to maintain OOP features. Hence it is not
mandatory to specify the access mode if we want the class to be inherited privately.
advertisement

13. If a derived class object is created, which constructor is called first?


a) Base class constructor
b) Derived class constructor
c) Depends on how we call the object
d) Not possible
View Answer
Answer: a
Explanation: First the base class constructor is invoked. When we create a derived class object, the
system tries to invoke its constructor but the class is derived so first the base class must be
initialized, hence in turn the base class constructor is invoked before derived class constructor.
14. The private members of the base class are visible in derived class but are not accessible
directly.
a) True
b) False
View Answer
Answer: a
Explanation: Consider that a variable is private in base class and the derived class uses public
inheritance to inherit that class. Now if we also have a global variable of same name as that of base
class private variable, neither the global variable nor the base class private variable will be
accessible from derived class. This is because we can’t have 2 variable with same name in same
local scope. Hence the private members are accessible but not directly.
15. How can you make the private members inheritable?
a) By making their visibility mode as public only
b) By making their visibility mode as protected only
c) By making their visibility mode as private in derived class
d) It can be done both by making the visibility mode public or protected
View Answer
Answer: d
Explanation: It is not mandatory that you have to make the visibility mode either public or protected.
You can do either of those. That will give you permission to inherit the private members of base
class.
1. How many types of inheritance are possible in C++?
a) 2
b) 3
c) 4
d) 5
View Answer
Answer: d
Explanation: There are five types of inheritance that are possible in C++. Single level, Multilevel,
multiple, hierarchical and hybrid. Here we count hybrid also because it sometimes can bring up a
new form of inheritance, Like inheritance using multiple and hierarchical, which sometimes results in
diamond problem.
2. Which among the following is true?
a) Java supports all types of inheritance
b) Java supports multiple inheritance
c) Java doesn’t support multiple inheritance
d) Java doesn’t support inheritance
View Answer
Answer: c
Explanation: Java doesn’t support multiple inheritance. This is done to avoid the diamond problem
that sometimes arises with inherited functions. Though, multiple inheritance can be implemented in
java using interfaces.
3. Which type of inheritance is illustrated by the following code?
class student{ public: int marks; };
class topper: public student { public: char grade; };
class average{ public: int makrs_needed; };
class section: public average{ public: char name[10]; };
class overall: public average{ public: int students; };

a) Single level
b) Multilevel and single level
c) Hierarchical
d) Hierarchical and single level
View Answer
Answer: c
Explanation: It is hierarchical inheritance and single level inheritance. Since class topper is inheriting
class student, it is single level inheritance. And then average is inherited by section and overall, so it
is hierarchical inheritance. But both of them are separate. Hence it is not hybrid inheritance.
4. Which among the following best describes multiple inheritance?
a) Two classes being parent of any other classes
b) Three classes being parent of other classes
c) More than one class being parent of other child classes
d) More than one class being parent of single child
View Answer
Answer: d
Explanation: If a class inherits more than one class, it is known as multiple inheritance. This should
not be referred with only two or three classes being inherited. But there must be one class which
inherits more than one class to be called as multiple inheritance.
5. How many types of inheritance can be used at a time in single program?
a) Any two types
b) Any three types
c) Any 4 types
d) Any type, any number of times
View Answer
Answer: d
Explanation: Any type of inheritance can be used in any program. There is no rule to use only few
types of inheritance. Only thing that matters is how the classes are inherited and used.
6. Which type of inheritance results in diamond problem?
a) Single level
b) Hybrid
c) Hierarchical
d) Multilevel
View Answer
Answer: b
Explanation: In diamond problem, hierarchical inheritance is used first, where two different classes
inherit the same class and then in turn a 4th class inherits the two classes which had inherited the
first class. Using more than one type of inheritance here, it is known as hybrid inheritance.
7. If 6 classes uses single level inheritance with pair classes (3 pairs), which inheritance will this be
called?
a) Single
b) Multiple
c) Hierarchical
d) Multilevel
View Answer
Answer: a
Explanation: Here all the pairs are using single inheritance. And no different pairs are inheriting
same classes. Hence it can’t be called hybrid or multilevel inheritance. You can say the single
inheritance is used 3 times in that program.
8. Which among the following is correct for the following code?
class A
{
public : class B
{
public : B(int i): data(i)
{
}
int data;
}
};
class C: public A
{
class D:public A::B{ };
};

a) Multi-level inheritance is used, with nested classes


b) Multiple inheritance is used, with nested classes
c) Single level inheritance is used, with enclosing classes
d) Single level inheritance is used, with both enclosing and nested classes
View Answer
Answer: d
Explanation: Class C is inheriting Class A. Class D is inheriting class B, both are nested. Hence it is
single inheritance. For multiple inheritance, class C or D should have inherited both class A and
class B.
advertisement

9. Which among the following is false?


a) If one class inherits the inherited class in single level inheritance, it is multi-level inheritance
b) Hybrid inheritance always contains multiple inheritance
c) Hierarchical inheritance involves inheriting same class into more than one classes
d) Hybrid inheritance can involve any types of inheritance together
View Answer
Answer: b
Explanation: It is not necessary to have multiple inheritance in hybrid type. It can have any type
together. This doesn’t have to be of specific type always.
10. If class A has two nested classes B and C. Class D has one nested class E, and have inherited
class A. If E inherits B and C, then:
a) It shows multiple inheritance
b) It shows hierarchical inheritance
c) It shows multiple inheritance
d) Multiple inheritance among nested classes, and single level for enclosing classes
View Answer
Answer: d
Explanation: This involves the same concept of inheritance, where the nested classes also follow the
inheritance rules. The Enclosing classes are having single inheritance. Nested classes involves
multiple.
11. In hierarchical inheritance, all the classes involve some kind of inheritance. (True/ False)
a) True
b) False
View Answer
Answer: b
Explanation: This is so because few classes might not be involved in any type of inheritance in
whole program whereas other classes might be participating in more than one type of inheritance at
the same time.
12. Which type of inheritance cannot involve private inheritance?
a) Single level
b) Multiple
c) Hybrid
d) All types can have private inheritance
View Answer
Answer: d
Explanation: This is a common type of inheritance where the protected and public members of
parent class become private members in child class. There is no type which doesn’t support private
inheritance.
13. How many classes can be inherited by a single class in multiple inheritance (C++)?
a) Only 2
b) Only 27
c) Only 1024
d) Any number of classes can be inherited
View Answer
Answer: d
Explanation: Any class can inherit any number of classes. There is no limit defined for the number of
classes being inherited by a single class.
14. How many classes can be inherited by a single class in java?
a) Only 1
b) Only 27
c) Only 255
d) Only 1024
View Answer
Answer: a
Explanation: Since java doesn’t support multiple inheritance, it is not possible for a class to inherit
more than 1 class in java. This is the same case in C# also.
15. If multi-level inheritance is used, First class B inherits class A, then C inherits B and so on. Till
how many classes can this go on?
a) Only till class C
b) Only till class J
c) Only till class Z
d) There is no limit
View Answer
Answer: d
Explanation: In this case there is no limit. All the classes going on like this will inherit the members of
base class, and hence the upper level inheritance won’t affect the number of classes that can go on
inheriting in this pattern.
1. Which among the following defines single level inheritance?
a) One base class derives another class
b) One derived class inherits from one base class
c) One base class inherits from one derived class
d) One derived class derives from another derived class
View Answer
Answer: b
Explanation: If only one base class is used to derive only one subclass, it is known as single level
inheritance. The reason of this name is that we inherit the base class to one more level and stop the
inheritance any further.
2. If class A and class B are derived from class C and class D, then ________________
a) Those are 2 pairs of single inheritance
b) That is multilevel inheritance
c) Those is enclosing class
d) Those are all independent classes
View Answer
Answer: a
Explanation: Since class A is derived from class C and then class B is derived from class D, there
are two pairs of classes which shows single inheritance. Those two pairs are independent of each
other though.
3. If single inheritance is used, program will contain ________________
a) At least 2 classes
b) At most 2 classes
c) Exactly 2 classes
d) At most 4 classes
View Answer
Answer: a
Explanation: The program will contain at least 2 classes in the sense of base and derived classes. At
least one base class and one derived class must be there. Types of inheritance remains the same
though.
4. Single level inheritance supports _____________ inheritance.
a) Runtime
b) Compile time
c) Multiple inheritance
d) Language independency
View Answer
Answer: a
Explanation: The runtime inheritance is done when object of a class is created to call a method. At
runtime the function is searched if it is in class of object. If not, it will search in its parent classes and
hierarchy for that method.
5. Which method in the code below is single level inherited?
class A
{
protected int a, b;
public: void show()
{
cout&lt;&lt;a&lt;&lt;b;
}
};
class B: public A
{
public: void disp()
{
cout&lt;&lt;a++&lt;&lt;b++;
}
};
class C: private A, public B
{
void avg()
{
cout&lt;&lt;(a+b)/2;
}
};

a) Class A
b) Class B
c) Class C
d) None
View Answer
Answer: b
Explanation: Class B is using single level inheritance. Class C is using multiple inheritance. And
class A is parent of other two classes.
6. If single level inheritance is used and an abstract class is created with some undefined functions,
can its derived class also skip some definitions?
a) Yes, always possible
b) Yes, possible if only one undefined function
c) No, at least 2 undefined functions must be there
d) No, the derived class must implement those methods
View Answer
Answer: d
Explanation: The derived class must implement those methods. This is because the parent class is
abstract and hence will have some undefined functions which has to be defined in derived classes.
Since we are using single level inheritance, if derived class doesn’t implement those functions then
one more class has to be there which will become multi-level inheritance.
7. Which among the following is false for single level inheritance?
a) There can be more than 2 classes in program to implement single inheritance
b) There can be exactly 2 classes to implement single inheritance in a program
c) There can be more than 2 independent classes involved in single inheritance
d) The derived class must implement all the abstract method if single inheritance is used
View Answer
Answer: c
Explanation: If more than 2 independent classes are involved to implement the single level
inheritance, it won’t be possible as there must be only one child and one parent class and none
other related class.
8. Which concept will result in derived class with more features (consider maximum 3 classes)?
a) Single inheritance
b) Multiple inheritance
c) Multilevel inheritance
d) Hierarchical inheritance
View Answer
Answer: b
Explanation: If single inheritance is used then only feature of a single class are inherited, and if
multilevel inheritance is used, the 2nd class might have use private inheritance. Hence only multiple
inheritance can result in derived class with more features. This is not mandatory but in a case if we
consider same number of features in each class, it will result the same.
9. Single level inheritance is safer than _____________
a) Multiple inheritance
b) Interfaces
c) Implementations
d) Extensions
View Answer
Answer: a
Explanation: Interfaces also represent a way of inheritance but is a wide word to decide which
inheritance we are talking about in it, hence can’t be considered. Implementation and extensions
also doesn’t match that level of specific idea. And multiple inheritance not so safe as it might result in
some ambiguity.
10. Which language doesn’t support single level inheritance?
a) Java
b) C++
c) Kotlin
d) All languages support it
View Answer
Answer: d
Explanation: All the languages support single level inheritance. Since any class can inherit other
classes as required, if single level inheritance was not allowed it would result in failing a lot of
features of OOP.
advertisement

11. Output of following program?


class A
{
protected: int a,b;
public: void disp()
{
cout&lt;&lt;a&lt;&lt;b;
}
};
class B:public A
{
int x,y;
};

a) Garbage value
b) Compile time error
c) Runtime error
d) Runs but gives random values as output
View Answer
Answer: b
Explanation: The compiler doesn’t find the main function and hence will throw an error main()
missing. This program is using single level inheritance but the program is incomplete. Every program
must implement main function.
12. Output of following program?
class A
{
float sal=40000;
}
class B extends A
{
int salBonus=10000;
public static void main(String args[])
{
B p=new B();
System.out.println("B salary is:"+p.sal);
System.out.println("Bonus of B is:"+p.bonus);
}
}

a) B salary is: 4000.0


Bonus of B is: 10000
b) B salary is 10000
Bonus of B is: 4000.0
c) Compile time error
d) Runtime error
View Answer
Answer: a
Explanation: The program gives output as in option a. The program have used single level
inheritance and hence have access to the parent class methods and variables. This program simply
prints the value from parent class and from the child class.
13. Single level inheritance will be best for___________
a) Inheriting a class which performs all the calculations
b) Inheriting a class which can print all the calculation results
c) Inheriting a class which can perform and print all calculations
d) Inheriting all the classes for different calculations
View Answer
Answer: b
Explanation: Inheriting a class which can perform the most common task will be more efficient. If
class which can perform all the calculations is inherited then there won’t be any problem to print the
result too. But if a class which can do the most common task for all the other tasks, it will make real
use of inheritance.
14. Which constructor will be called first from the classes involved in single inheritance from object of
derived class?
a) Base class constructor
b) Derived class constructor
c) Both class constructors at a time
d) Runtime error
View Answer
Answer: a
Explanation: The base class constructor will be called first from the object of derived class
constructor. When the derived class members are to be initialized and allocated memory, the base
class members should also be confirmed with the memory allocation.
15. If base class contains 2 nested classes, will it be possible to implement single level inheritance?
a) Yes, always
b) Yes, only if derived class also have nested classes
c) No, it will use more than 2 classes which is wrong
d) No, never
View Answer
Answer: a
Explanation: The nested classes are also members of a class. They behave as a used defined data
type with some methods implementation. So the inheritance will be as usual with the nested classes
being member of base class and of derived class if not private.
1. Which among the following is best to define hierarchical inheritance?
a) More than one classes being derived from one class
b) More than 2 classes being derived from single base class
c) At most 2 classes being derived from single base class
d) At most 1 class derived from another class
View Answer
Answer: a
Explanation: When two or more classes get derived from a single base class, it is known as
hierarchical inheritance. This gives us freedom to use same code with different scopes and flexibility
into different classes.
2. Do members of base class gets divided among all of its child classes ?
a) Yes, equally
b) Yes, depending on type of inheritance
c) No, it’s doesn’t get divided
d) No, it may or may not get divided
View Answer
Answer: c
Explanation: The class members doesn’t get divided among the child classes. All the members get
derived to each of the subclasses as whole. The only restriction is from the access specifiers used.
3. Each class can inherit the base class ________________
a) Independently using any inheritance
b) Independently with private inheritance only
c) With same type of inheritance
d) With each class using different inheritance only
View Answer
Answer: a
Explanation: The classes can inherit the base class using any type of inheritance. There is no
mandatory condition to use same private,public or protected inheritance only.
4. How many classes must be there to implement hierarchical inheritance ?
a) Exactly 3
b) At least 3
c) At most 3
d) At least 1
View Answer
Answer: b
Explanation: At least 3 classes must be there. Two derived classes and one base class. This lets us
implement two classes that have common characteristics from base class.
5. Base class _______________
a) Can be made abstract
b) Can’t be made abstract
c) Must be abstract
d) If made abstract, compile time error
View Answer
Answer: a
Explanation: The base class may or may not be declared abstract. It depends on the need of
program. If it is made abstract, it can contain undefined functions too. In turn, those functions will
have to be implemented by each of the derived classes.
6. Which access specifiers should be used so that all the derived classes restrict further inheritance
of base class members?
a) Private
b) Public
c) Protected
d) Any inheritance type can be used
View Answer
Answer: a
Explanation: All the derived classes must use private inheritance. This will make the members of
base class private in derived classes. Hence none of the members of base class will be available for
further inheritance.
7. Which class uses hierarchical inheritance in following code?
class A
{
int a;
};
class B:class A
{
int b;
};
class C:class A,class B
{
int c;
};
class D:class A
{
int d;
};

a) Class A,B,C
b) Class B,C,D
c) Class A,C,D
d) Class D,A,B
View Answer
Answer: d
Explanation: Class A is base class and B and D are derived classes. If class C is considered, it
shows hybrid inheritance, involving single level and multiple inheritance.
8. Which among the following is correct for following code ?
abstract class A
{
public Int a;
public void disp();
};
class B:public A
{
public: void dis()
{
court&lt;&lt;a;
}
};
class C:private A
{
public void incr()
{
a++;
}
}
void main()
{
B b.disp();
}

a) Compile time error


b) Runtime error
c) Program runs and o/p is 0
d) Program runs and o/p is garbage value
View Answer
Answer: a
Explanation: The derived class D have not implemented the undefined function. Here the main
concept involves hierarchical inheritance with abstract base class.
advertisement

9. How many classes can be derived from the base class using hierarchical inheritance?
a) As many as required
b) Only 7
c) Only 3
d) Up to 127
View Answer
Answer: a
Explanation: The number of classes that can be derived from a base class doesn’t have any
restriction and hence will be able to derive as many classes as required. This feature gives more
flexibility and code reusability.
10. If one class have derived the base class privately then another class can’t derive the base class
publically.
a) True
b) False
View Answer
Answer: b
Explanation: The classes are independent and can access the base class and inherit it in whichever
way it is required. The classes can use the base base class members privately or publically
maintaining the security of data and methods.
11. Which among the following is true ?
a) Hierarchical inheritance is subset of multiple inheritance
b) Hierarchical inheritance is strongest inheritance type
c) Hierarchical inheritance uses only 2 classes for implementation
d) Hierarchical inheritance allows inheritance of common features to more than one class
View Answer
Answer: d
Explanation: Hierarchical inheritance is used to make all the inherited classes have some common
features obtained from a single base class. This allows all the classes to maintain a group or to be
classified under one class.
12. Hierarchical inheritance can be a subset of _________________
a) Hybrid inheritance
b) Multiple inheritance
c) Single level inheritance
d) Multilevel inheritance
View Answer
Answer: a
Explanation: When we use hybrid inheritance, it can contain any type of inheritance or combination
or more than two types. Hence it may contain Hierarchical inheritance too, hence it can be subset of
hybrid inheritance.
13. Which type of inheritance is most suitable for inheriting Same syllabus into different colleges with
different streams?
a) Multiple
b) Single
c) Hierarchical
d) Multilevel
View Answer
Answer: c
Explanation: When hierarchical inheritance is used, the common syllabus can be adopted into
different college classes where the same syllabus is applicable. For changing the syllabus only the
details of base class will have to changed.
14. Which class constructor is called first when an object of derived class is created?
a) Base class constructor
b) Derived class constructor
c) Firstly created derived class constructor
d) Last created derived class constructor
View Answer
Answer: a
Explanation: The base class must be initialised first hence the constructor of base class is called
first. This makes everything ready for the new object being created.
15. All the derived classes can access only few members of base class that other derived classes
can’t access at same time, in hierarchical inheritance.
a) True
b) False
View Answer
Answer: b
Explanation: The derived classes have full access to all the non private member’s of base class.
Every derived class have equal access, none of the class can have special access to specific
members of base class in general cases.
1. Which among the following best defines multilevel inheritance?
a) A class derived from another derived class
b) Classes being derived from other derived classes
c) Continuing single level inheritance
d) Class which have more than one parent
View Answer
Answer: b
Explanation: Only if the class is being derived from other derived class, it can be called as multilevel
inheritance. If a class is derived from another class, it is single level inheritance. There must be more
than one level of inheritance.
2. If there are 5 classes, E is derived from D, D from C, C from B and B from A. Which class
constructor will be called first if the object of E or D is created?
a) A
b) B
c) C
d) A and B
View Answer

3. If there are 3 classes. Class C is derived from class B and B is derived from A, Which class
destructor will be called at last if object of C is destroyed.
a) A
b) B
c) C
d) All together
View Answer
Answer: a
Explanation: The destructors are called in the reverse order of the constructors being called. Hence
in multilevel inheritance, the constructors are created from parent to child, which leads to destruction
from child to parent. Hence class A destructor will be called at last.
4. Which Class is having highest degree of abstraction in multilevel inheritance of 5 levels?
a) Class at 1st level
b) Class 2nd last level
c) Class at 5th level
d) All with same abstraction
View Answer
Answer: a
Explanation: The class with highest degree of abstraction will be the class at the 1st level. You can
look at a simple example like, a CAR is more abstract than SPORTS CAR class. The level of
abstraction decrease with each level as more details comes out.
5. If all the classes use private inheritance in multilevel inheritance then ______________
a) It will not be called multilevel inheritance
b) Each class can access only non-private members of its parent
c) Each subsequent class can access all members of previous level parent classes
d) None of the members will be available to any other class
View Answer
Answer: b
Explanation: The classes will be able to access only the non-private members of its parent class.
The classes are using private inheritance, hence all the members of parent class become private in
the derived class. In turn those won’t be allowed for further inheritance or direct access outside the
class.
6. Multilevel inheritance allows _________________ in the program.
a) Only 7 levels of inheritance
b) At least 7 levels of inheritance
c) At most 16 levels of inheritance
d) As many levels of inheritance as required
View Answer
Answer: d
Explanation: The multilevel inheritance allows any number of levels of inheritance. This is the
maximum flexibility feature to make the members available to all the new classes and to add their
own functionalities. The code reusability is used too.
7. What is minimum number of levels for a implementing multilevel inheritance?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: c
Explanation: There must be at least 3 levels of inheritance. Otherwise if less, it will be single level
inheritance or would have got no inheritance implemented. There must be a derived class from
which another class is derived.
8. In multilevel inheritance one class inherits _______________
a) Only one class
b) More than one class
c) At least one class
d) As many classes as required
View Answer
Answer: a
Explanation: The classes inherit only from one class. This continues as each class inherits only one
class. There should not be any class which inherits from two or more classes or which have more
than one subclass.
9. All the classes must have all the members declared private to implement multilevel inheritance.
a) True
b) False
View Answer
Answer: b
Explanation: There is no mandatory rule to make the members private for multilevel inheritance.
Moreover if all the classes have only the private members then there won’t be any member to get
inherited. Hence the working will be of no use.
10. Can abstract classes be used in multilevel inheritance?
a) Yes, always
b) Yes, only one abstract class
c) No, abstract class doesn’t have constructors
d) No, never
View Answer
Answer: a
Explanation: The abstract classes can always be used in multilevel inheritance. The only condition
that may arise is that all the undefined functions must be defined in subclasses. There must not be
any undefined function.
11. How many abstract classes can be used in multilevel inheritance?
a) Only 1
b) Only 2
c) At least one less than number of levels
d) Can’t be used
View Answer
Answer: c
Explanation: At least one class must implement all the undefined functions. Hence there must be at
least one class which is not abstract. That is at least one less than number of levels.
12. If all the classes used parameterized constructors and no default constructor then, ___________
a) The object of lower level classes can’t be created
b) Object of lower level classes must call parent class constructors explicitly
c) Object of lower level classes must define all the default constructors
d) Only object of first class can be created, which is first parent
View Answer
Answer: b
Explanation: Each class constructor must be called before creating object of any subclass. Hence it
will be mandatory to call the constructors of parent classes explicitly with parameters. This will make
all the previous class member be initialized and then the class in use will be able to create the
object.
advertisement

13. In multilevel inheritance, which is the most significant feature of OOP used?
a) Code readability
b) Flexibility
c) Code reusability
d) Code efficiency
View Answer
Answer: c
Explanation: The classes using multilevel inheritance will use the code in all the subsequent
subclasses if available. Hence the most significant feature among the options given is code
reusability. This feature is generally intended to use the data values and reuse the redundant
functions.
14. Does following code show multiple inheritance?

class A
{
int a;
};
class B
{
int b;
};
class C:public A, public B
{
int c;
};
class D:public C
{
int d;
};
a) Yes, class C and class D
b) Yes, All together it’s multilevel
c) No, 4 classes are used
d) No, multiple inheritance is used with class A, B and C
View Answer
Answer: d
Explanation: Since multiple inheritance is used to derive class C and then class D is derived from
class C. This is not multilevel inheritance. The classes should derive from single class. This is
actually hybrid inheritance.
15. Is it compulsory for all the classes in multilevel inheritance to have constructors defined explicitly
if only last derived class object is created?
a) Yes, always
b) Yes, to initialize the members
c) No, it not necessary
d) No, Constructor must not be defined
View Answer
Answer: c
Explanation: It’s not mandatory to define the constructors explicitly. Default constructor will always
be provided by the compiler itself if none another constructor is defined in those classes. If explicit
default constructor is defined it will be used.
1. Multiple inheritance is ____________________
a) When a class is derived from another class
b) When a class is derived from two or more classes
c) When a class is derived from other two derived classes
d) When a class is derived from exactly one class
View Answer
Answer: b
Explanation: The multiple inheritance is used when a class is being derived using two base classes
or more. This way a single class can have features of more than one classes inherited into a single
unit. This lets us combine two class members into a single class.
2. Which problem arises due to multiple inheritance, if hierarchical inheritance is used previously for
its base classes?
a) Diamond
b) Circle
c) Triangle
d) Loop
View Answer
Answer: a
Explanation: The diamond problem arises when multiple inheritance is used. This problem arises
because the same name member functions get derived into a single class. Which in turn creates
ambiguity in calling those methods.
3. How many classes should a program contain to implement the multiple inheritance?
a) Only 1
b) At least 1
c) At least 3
d) Exactly 3
View Answer
Answer: c
Explanation: For the implementation of multiple inheritance, there must be at least 3 classes in a
program. At least 2 base classes and one class to inherit those two classes. If lesser, it becomes
single level inheritance.
4. Which programming language restricts the use of multiple inheritance?
a) C++
b) PHP
c) SmallTalk
d) Java
View Answer
Answer: d
Explanation: Java doesn’t allow use of multiple inheritance with classes. But this can be done by
using the interfaces. This is more secure and unambiguous way to implement multiple inheritance.
5. Is it possible to have all the abstract classes as base classes of a derived class from those?
a) Yes, always
b) Yes, only if derived class implements all the methods
c) No, because abstract classes doesn’t have constructors
d) No, never
View Answer
Answer: b
Explanation: The condition for abstract class applies same here too. All the undefined functions must
be defined. Hence all the base classes can be abstract but derived class must implement all those
undefined functions.
6. If class A inherits class B and class C as “class A: public class B, public class C {// class body ;}; ”,
which class constructor will be called first?
a) Class A
b) Class B
c) Class C
d) All together
View Answer
Answer: b
Explanation: The constructors of parent class will be called first. In that, the constructor of the
classes will be called in the same sequence as that mentioned in class definition inheritance. Since
class B is mentioned first for inheritance, its constructor will be called first.
7. Why does diamond problem arise due to multiple inheritance?
a) Methods with same name creates ambiguity and conflict
b) Methods inherited from the superclass may conflict
c) Derived class gets overloaded with more than two class methods
d) Derived class can’t distinguish the owner class of any derived method
View Answer
Answer: a
Explanation: All the derived classes can distinguish the base class members, but if a method is
being inherited to the base classes from another class which again gets inherited into same class
(diamond shape), that may create conflict in using the function from two available.
8. How many base classes can a derived class have which is implementing multiple inheritance?
a) Only 2
b) At least 2
c) At most 2
d) As many as required
View Answer
Answer: d
Explanation: The classes can derive from as many classes as required since the multiple inheritance
feature is made to combine or group together the functions that are from different classes. This
make the derived class stronger in terms of its flexibility.
9. How to overcome diamond problem ?
a) Using alias name
b) Using seperate derived class
c) Using virtual keyword with same name function
d) Can’t be done
View Answer
Answer: c
Explanation: To overcome the ambiguity and conflict we can use keyword virtual. This will help us to
differentiate the functions with same name that came to last derived class in diamond problem.
10. When multiple inheritance is used, which class object should be used in order to access all the
available members of parent and derived class ?
a) Derived class object
b) Parent class objects
c) Use Abstract derived class
d) Derive a class from derived class
View Answer
Answer: a
Explanation: The derived class object can access all of its own members. It can also access the
available members of the parent classes, because the members are derived into the derived class.
11. If all the members of all the base classes are private then,
a) There won’t be any use of multiple inheritance
b) It will make those members public
c) Derived class can still access them in multiple inheritance
d) Compile time error
View Answer
Answer: a
Explanation: The derived class will not be able to access any members of the base classes. Since
private member’s are not inheritable. It leads to no use of multiple inheritance.
12. Is it compulsory to have constructor for all the classes involved in multiple inheritance?
a) Yes, always
b) Yes, only if no abstract class is involved
c) No, only classes being used should have a constructor
d) No, they must not contain constructors
View Answer
Answer: b
Explanation: The constructors must be defined in every class. If class is abstract, it won’t have any
constructor but other classes must have constructor. Either implicit or explicit.
advertisement

13. If a class contains 2 nested class and is being inherited by another class, will there be any
multiple inheritance?
a) No, only single level inheritance is used
b) No, only multilevel inheritance is used
c) Yes, because 3 classes are involved
d) Yes, because more than 1 classes are being derived
View Answer
Answer: a
Explanation: When a class having nested classes is being derived into another class. It indirectly
means a simple class is being inherited to another class. This is single level inheritance.
14. Which members can’t be accessed in derived class in multiple inheritance ?
a) Private members of base
b) Public members of base
c) Protected members of base
d) All the members of base
View Answer
Answer: a
Explanation: The private member’s are available for only the class containing those members.
Derived classes will have access to protected and public members only.
15. Can the derived class be made abstract if multiple inheritance is used ?
a) No, because other classes must be abstract too
b) Yes, if all the functions are implemented
c) Yes, if all the methods are predefined
d) No, since constructors won’t be there
View Answer
Answer: d
Explanation: The derived class must not be abstract. This is because the abstract classes doesn’t
have constructor and hence we won’t be having capability to have instances. This will restrict use of
multiple inheritance.
1. Which among the following is best to define hierarchical inheritance?
a) More than one classes being derived from one class
b) More than 2 classes being derived from single base class
c) At most 2 classes being derived from single base class
d) At most 1 class derived from another class
View Answer
Answer: a
Explanation: When two or more classes get derived from a single base class, it is known as
hierarchical inheritance. This gives us freedom to use same code with different scopes and flexibility
into different classes.
2. Do members of base class gets divided among all of its child classes ?
a) Yes, equally
b) Yes, depending on type of inheritance
c) No, it’s doesn’t get divided
d) No, it may or may not get divided
View Answer
Answer: c
Explanation: The class members doesn’t get divided among the child classes. All the members get
derived to each of the subclasses as whole. The only restriction is from the access specifiers used.
3. Each class can inherit the base class ________________
a) Independently using any inheritance
b) Independently with private inheritance only
c) With same type of inheritance
d) With each class using different inheritance only
View Answer
Answer: a
Explanation: The classes can inherit the base class using any type of inheritance. There is no
mandatory condition to use same private,public or protected inheritance only.
4. How many classes must be there to implement hierarchical inheritance ?
a) Exactly 3
b) At least 3
c) At most 3
d) At least 1
View Answer
Answer: b
Explanation: At least 3 classes must be there. Two derived classes and one base class. This lets us
implement two classes that have common characteristics from base class.
5. Base class _______________
a) Can be made abstract
b) Can’t be made abstract
c) Must be abstract
d) If made abstract, compile time error
View Answer
Answer: a
Explanation: The base class may or may not be declared abstract. It depends on the need of
program. If it is made abstract, it can contain undefined functions too. In turn, those functions will
have to be implemented by each of the derived classes.
6. Which access specifiers should be used so that all the derived classes restrict further inheritance
of base class members?
a) Private
b) Public
c) Protected
d) Any inheritance type can be used
View Answer
Answer: a
Explanation: All the derived classes must use private inheritance. This will make the members of
base class private in derived classes. Hence none of the members of base class will be available for
further inheritance.
7. Which class uses hierarchical inheritance in following code?
class A
{
int a;
};
class B:class A
{
int b;
};
class C:class A,class B
{
int c;
};
class D:class A
{
int d;
};

a) Class A,B,C
b) Class B,C,D
c) Class A,C,D
d) Class D,A,B
View Answer
Answer: d
Explanation: Class A is base class and B and D are derived classes. If class C is considered, it
shows hybrid inheritance, involving single level and multiple inheritance.
8. Which among the following is correct for following code ?
abstract class A
{
public Int a;
public void disp();
};
class B:public A
{
public: void dis()
{
court&lt;&lt;a;
}
};
class C:private A
{
public void incr()
{
a++;
}
}
void main()
{
B b.disp();
}

a) Compile time error


b) Runtime error
c) Program runs and o/p is 0
d) Program runs and o/p is garbage value
View Answer
Answer: a
Explanation: The derived class D have not implemented the undefined function. Here the main
concept involves hierarchical inheritance with abstract base class.
advertisement

9. How many classes can be derived from the base class using hierarchical inheritance?
a) As many as required
b) Only 7
c) Only 3
d) Up to 127
View Answer
Answer: a
Explanation: The number of classes that can be derived from a base class doesn’t have any
restriction and hence will be able to derive as many classes as required. This feature gives more
flexibility and code reusability.
10. If one class have derived the base class privately then another class can’t derive the base class
publically.
a) True
b) False
View Answer
Answer: b
Explanation: The classes are independent and can access the base class and inherit it in whichever
way it is required. The classes can use the base base class members privately or publically
maintaining the security of data and methods.
11. Which among the following is true ?
a) Hierarchical inheritance is subset of multiple inheritance
b) Hierarchical inheritance is strongest inheritance type
c) Hierarchical inheritance uses only 2 classes for implementation
d) Hierarchical inheritance allows inheritance of common features to more than one class
View Answer
Answer: d
Explanation: Hierarchical inheritance is used to make all the inherited classes have some common
features obtained from a single base class. This allows all the classes to maintain a group or to be
classified under one class.
12. Hierarchical inheritance can be a subset of _________________
a) Hybrid inheritance
b) Multiple inheritance
c) Single level inheritance
d) Multilevel inheritance
View Answer
Answer: a
Explanation: When we use hybrid inheritance, it can contain any type of inheritance or combination
or more than two types. Hence it may contain Hierarchical inheritance too, hence it can be subset of
hybrid inheritance.
13. Which type of inheritance is most suitable for inheriting Same syllabus into different colleges with
different streams?
a) Multiple
b) Single
c) Hierarchical
d) Multilevel
View Answer
Answer: c
Explanation: When hierarchical inheritance is used, the common syllabus can be adopted into
different college classes where the same syllabus is applicable. For changing the syllabus only the
details of base class will have to changed.
14. Which class constructor is called first when an object of derived class is created?
a) Base class constructor
b) Derived class constructor
c) Firstly created derived class constructor
d) Last created derived class constructor
View Answer
Answer: a
Explanation: The base class must be initialised first hence the constructor of base class is called
first. This makes everything ready for the new object being created.
15. All the derived classes can access only few members of base class that other derived classes
can’t access at same time, in hierarchical inheritance.
a) True
b) False
View Answer
Answer: b
Explanation: The derived classes have full access to all the non private member’s of base class.
Every derived class have equal access, none of the class can have special access to specific
members of base class in general cases.
1. Which among the following best defines the hybrid inheritance?
a) Combination of two or more inheritance types
b) Combination of same type of inheritance
c) Inheritance of more than 7 classes
d) Inheritance involving all the types of inheritance
View Answer
Answer: a
Explanation: When more than one type of inheritance are used together, it results in new type of
inheritance which is in general known as hybrid inheritance. This may of may not have better
capabilities.
2. How many types of inheritance should be used for hybrid ?
a) Only 1
b) At east 2
c) At most two
d) Always more than 2
View Answer
Answer: b
Explanation: There must be combination of at least 2 types of inheritance. The inheritance should be
of different type.
3. If single inheritance is used with class A and B. A is base class. Then class C,D and E where C is
base class and D is derived from C, then E is derived from D. Class C is made to inherit from class
B. Which is the resultant type ?
a) Single level
b) Multilevel
c) Hybrid
d) Multiple
View Answer
Answer: b
Explanation: The statement represents multilevel inheritance. It is not hybrid since looking at
complete idea, one can’t differentiate whether two type of inheritance are used. Hence it is multilevel
inheritance.
4. Diamond problem includes ____________________ hybrid inheritance
a) Hierarchical and Multiple
b) Hierarchical and Hierarchical
c) Multiple and Multilevel
d) Single, Hierarchical and Multiple
View Answer
Answer:a
Explanation: The diamond problem arises when more than one classes are derived from one class
and then those classes are used to derive single clas. Resulting in ambiguity of same functions from
each class.
5. If __________________ inheritance is done continuously, it is similar to tree structure.
a) Hierarchical
b) Multiple
c) Multilevel
d) Hierarchical and Multiple
View Answer
Answer: a
Explanation: Hierarchical inheritance is deriving more than one classes from a base class, it it is
done continuously and subsequently, it results forming a tree like structure of classes being linked.
6. Which amongst the following is true for hybrid inheritance?
a) Constructor calls are in reverse
b) Constructor calls are priority based
c) Constructor of only derived class is called
d) Constructor calls are usual
View Answer
Answer: d
Explanation: The constructors will be called in usual way. First the parent class Constructor and then
the derived class Constructors. This is done to initialise all the members properly.
7. Which type of inheritance must be used so that the resultant is hybrid?
a) Multiple
b) Hierarchical
c) Multilevel
d) None
View Answer
Answer: d
Explanation: The use of any specific type is not necessary. Though the final structure should not be
the same, it should represent more than one type of inheritance if class diagram is drawn.
8. The private member’s are made public to all the classes in inheritance.
a) True
b) False
View Answer
Answer: b
Explanation: The private member’s scope can’t be changed and those can never be accessed in
other classes. Only the class containing private member’s can access its own members.
9. If hierarchical inheritance requires to inherit more than one class to single class, which syntax is
correct? ( A,B,C are class names )
a) hierarchical class A: public B, public C
b) multiple class A: public B, public C
c) many class A: public B, public C
d) class A: public B, public C
View Answer
Answer: d
Explanation: The syntax is as same as declaration of other classes. There is no specific keyword
defined for using hybrid inheritance in programming. Only thing is to specify the class name
separated by commas.
10. What is the maximum number of classes allowed in hybrid inheritance?
a) 7
b) 127
c) 255
d) As many as required
View Answer
Answer: d
Explanation: The classes in any type of inheritance can inherit as many classes as required. The
only condition that may arise is memory management. The classes can inherit most of the features
from more than one class.
11. What is the minimum number of classes to be there in a program implementing hybrid
inheritance?
a) 2
b) 3
c) 4
d) No limit
View Answer
Answer: d
Explanation: The answer is no limit. There is no condition defined for limit of classes that has to be
used in hybrid. Though you must have at least 4 classes so that one set of multiple or hierarchical
inheritance is there and one more class to use single level inheritance.
12. If object of lowest level class is created ( last derived class ), _________________ of its parent
class constructors are called.
a) Few
b) All
c) Only parent and parent
d) Base and Derived
View Answer
Answer: c
Explanation: When derived class object is created, all of its successor parent classes constructors
are called. Constructor of all the connected classes is not created. Since the parent members have
to be initialised, but other derived classes are not needed.
advertisement

13. If hybrid inheritance is used, it mostly shows _______________ feature of OOP.


a) Flexibility
b) Reusability
c) Efficiency
d) Code readability
View Answer
Answer: b
Explanation: The code is reusable in most of the classes and the data becomes more linked to other
classes. Other features are also exhibited, but the code reusability is used the most. Code
readability becomes relatively less. Flexibility increases but it depends on how the hybrid inheritance
is used.
14. The sequence of destructors being called while using hybrid inheritance is ____________
a) Reverse of constructors being called
b) Reverse of classes being made
c) Reverse of objects being created
d) Reverse of code calling objects
View Answer
Answer: a
Explanation: The destructors are always called in reverse order of constructors being called always.
The type of inheritance doesn’t matter. The only important concept is the sequence of classes being
inherited.
15. Overloading operators are possible only by using hybrid inheritance.
a) True
b) False
View Answer
Answer: b
Explanation: The overloading concept is not related to the types of inheritance being used.
Overloading operators can be done without using inheritance. You don’t even have to use more than
one class for operator overloading.
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) both 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.
advertisement

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++.

Вам также может понравиться