250+ TOP MCQs on Types of Inheritance and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Types of Inheritance”.

1. How many types of inheritance are possible in C++?
a) 2
b) 3
c) 4
d) 5
Answer: d
Clarification: 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
Answer: c
Clarification: 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
Answer: c
Clarification: 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
Answer: d
Clarification: 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 a single program?
a) Any two types
b) Any three types
c) Any 4 types
d) Any type, any number of times
Answer: d
Clarification: 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 the diamond problem?
a) Single level
b) Hybrid
c) Hierarchical
d) Multilevel
Answer: b
Clarification: 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
Answer: a
Clarification: 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
Answer: d
Clarification: 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.

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
Answer: b
Clarification: 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
Answer: d
Clarification: 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.
a) True
b) False
Answer: b
Clarification: 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
Answer: d
Clarification: 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
Answer: d
Clarification: 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
Answer: a
Clarification: 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
Answer: d
Clarification: 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.

250+ TOP MCQs on Catching Class Types and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Catching Class Types”.

1. Which among the following is true for class exceptions?
a) Only base class can give rise to exceptions
b) Only derived class can give rise to exceptions
c) Either base class or derived class may produce exceptions
d) Both base class and derived class may produce exceptions
Answer: d
Clarification: It’s not mandatory that either base class or derived class can give rise to exceptions. The exceptions might get produced from any class. The exceptions depends on code.

2. If both base and derived class caught exceptions ______________
a) Then catch block of derived class must be defined before base class
b) Then catch block of base class must be defined before the derived class
c) Then catch block of base and derived classes doesn’t matter
d) Then catch block of base and derived classes are not mandatory to be defined
Answer: a
Clarification: It is a condition for writing the catch blocks for base and derived classes. It is mandatory to write derived class catch block first because the errors produced by the derived class must be handled first.

3. Which among the following is true?
a) If catch block of base class is written first, it is compile time error
b) If catch block of base class is written first, it is run time error
c) If catch block of base class is written first, derived class catch block can’t be reached
d) If catch block of base class is written first, only derived class catch block is executed
Answer: c
Clarification: If the catch block of the base class is defined first and then the derived class catch block is given. The code becomes unreachable. Hence the derived class catch block must be written first.

4. The catching of base class exception ___________________________ in java.
a) After derived class is not allowed by compiler
b) Before derived class is not allowed by compiler
c) Before derived class is allowed
d) After derived class can’t be done
Answer: b
Clarification: The catching of base class exception before derived class is not allowed in java. The compiler itself doesn’t allow this declaration. It produces an error.

5. If catching of base class exception is done before derived class in C++ ________________
a) It gives compile time error
b) It doesn’t run the program
c) It may give warning but not error
d) It always gives compile time error
Answer: c
Clarification: The compiler in C++ doesn’t identify this as compile time error and allows the execution of the program. But, the compiler may give some warning related to the catch block sequence or code unreachable.

6. How many catch blocks can a class have?
a) Only 1
b) 2
c) 3
d) As many as required
Answer: d
Clarification: There are many type of exceptions that may arise while running a code. And each catch block can handle only one exception. Hence there can be as many catch blocks as required.

7. Since which version of java is multiple exception catch was made possible?
a) Java 4
b) Java 5
c) Java 6
d) Java 7
Answer: d
Clarification: None of the languages used to support multiple exception catch in a single catch block. Since java 7 the feature was added to catch more than one exceptions in one catch block.

8. To catch more than one exception in one catch block, how are the exceptions separated in the syntax?
a) Vertical bar
b) Hyphen
c) Plus
d) Modulus
Answer: a
Clarification: Just the way we separate the arguments in a function definition using comma. Here we separate the exceptions by using a vertical bar or we call it pipe symbol sometimes. This is just a convention followed to separate different exception list.

9. If a catch block accepts more than one exceptions then __________________
a) The catch parameters are not final
b) The catch parameters are final
c) The catch parameters are not defined
d) The catch parameters are not used
Answer: b
Clarification: The catch parameters are made final. This is to ensure that the parameters are not changed inside the catch block. Hence those retain their values.

10. Which among the following handles the undefined class in program?
a) ClassNotFound
b) NoClassException
c) ClassFoundException
d) ClassNotFoundException
Answer: d
Clarification: It is the exception handler that handles the exceptions when the class used is not found in the program. This is done to handle all the undefined class exceptions. This can be due to a command line error.

11. If classes produce some exceptions, then ______________________
a) Their respective catch block must be defined
b) Their respective catch blocks are not mandatory
c) Their catch blocks should be defined inside main function
d) Their catch blocks must be defined at the end of program
Answer: a
Clarification: The catch blocks must be defined. This is to ensure that all the exceptions related to the classes are handled by the program code and the program doesn’t terminate unexpectedly.

12. Which among the following is true?
a) Only the base class catch blocks are important
b) Only the derived class catch blocks are important
c) Both the base and derived class catch blocks are important
d) If base and derived classes both produce exceptions, program doesn’t run
Answer: c
Clarification: The purpose of exception handling is to handle the unexpected errors in the program. If base class might produce some error then its catch block must be given and if the derived class might produce some error then it must be given a specific catch block too.

13. Which is the necessary condition to define the base and derived class catch blocks?
a) Base class catch should be defined first
b) Derived class catch should be defined first
c) Catch block for both the classes must not be defined
d) Catch block must be defined inside main function
Answer: b
Clarification: The derived class catch blocks must be defined prior to the base class catch block. This is to ensure that all the catch boxes are reachable. If not done, the code might become unreachable which in turn makes the program prone to errors.

14. Only the base class catch box can handle more than one exception in single block.
a) True
b) False
Answer: b
Clarification: There is no specific condition that states that only base class catch box can handle more than one exception in single box. Even the derived class catch clocks can handle more than one exceptions.

15. Which condition among the following might result in memory exception?
a) False if conditions
b) Nested if conditions that are all false
c) Infinite loops
d) Loop that runs exactly 99 times
Answer: c
Clarification: The infinite loops doesn’t stop running once started. There must be a way to stop the loop but that is always an improper termination. Infinite loops may keep on using more memory and hence would result in memory error.

250+ TOP MCQs on Inbuilt Classes and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Inbuilt Classes”.

1. What are inbuilt classes?
a) The predefined classes in a language
b) The classes that are defined by the user
c) The classes which are meant to be modified by the user
d) The classes which can’t be used by the user
Answer: a
Clarification: The classes that are already provided in a programming language for use are inbuilt classes. These classes provide some functions or objects that can be used by the programmer for easier code.

2. Inbuilt class __________________________
a) Must be included before use
b) Are not necessary to be included for use
c) Are used by the compiler only
d) Can be modified by programmer always
Answer: a
Clarification: The inbuilt classes must be included in the program. Whenever some functions are used, they must have a declaration before use. The same is the case with classes.

3. What doesn’t inbuilt classes contain?
a) Function prototype
b) Function declaration
c) Function definitions
d) Objects
Answer: c
Clarification: The classes contain the definitions of the special functions that are provided for the programmers use. Those functions can be used to make the programming easy and to reuse the already existing code.

4. Which among the following not an inbuilt class in C++?
a) System
b) Color
c) String
d) Functions
Answer: d
Clarification: There is no inbuilt class named function in java. The others are classes already provided in java. All those classes contain some special functions to be used in programming.

5. What is the InputStream class meant for?
a) To handle all input streams
b) To handle all output streams
c) To handle all input and output streams
d) To handle only input from file
Answer: a
Clarification: The InputStream is an inbuilt class which is used to handle all the tasks related to input handling. This class extends input from keyboard or file or any other possible input stream.

6. Which statement is true for the Array class?
a) Arrays can have variable length
b) The length array can be changed
c) Each class has an associated Array class
d) Arrays can contain different type of values
Answer: c
Clarification: The Array class is associated with all the other classes. This gives us the flexibility to declare an array of any type. The index goes from 0 to n, where n is some fixed size for array.

7. What is the use of Math class?
a) To use the mathematical functions with strings
b) To use the mathematical functions
c) To suppress the use of mathematical functions
d) To complex the calculations
Answer: b
Clarification: The Math class is provided with some special functions. These functions can be used to calculate and get result of some special and usual mathematical functions. We don’t have to write the code to calculate the trigonometric function results, instead we can use Math functions.

8. DataInputStream is derived from ______________________
a) StreamingInput
b) StreamedInput
c) StreameInput
d) StreamInput
Answer: d
Clarification: The DataInputStream is more specific class for operating on specific type of data inputs. This is used to read data of specific type. The same can be used to read data in a specific format.

9. Which attribute can be used to get the size of an array?
a) Size.Array
b) Array.Size
c) Array_name.length
d) length.Array_name
Answer: c
Clarification: The array name is given of which the length have to be calculated. The array length is stored in the attribute length. Hence we access it using dot operator.

10. Number class can’t manipulate ____________________
a) Integer values
b) Float values
c) Byte values
d) Character values
Answer: d
Clarification: The Number class is used to work with all the number type of values. The integers, float, double, byte etc. are all number type values. Character is not a number value.

11. Which function should be used to exit from the program that is provided by System class?
a) exit(int);
b) gc();
c) terminate();
d) halt();
Answer: a
Clarification: The exit function should be used to terminate the program. The function is passed with an argument. The argument indicated the type of error occurred.

12. Which class contain runFinalization() method?
a) Finalize
b) System
c) Final
d) SystemFinal
Answer: b
Clarification: The runFinalization() Function is defined in the System class. The function is used to finalize an object which undergo destruction. The action is required to terminate the object properly.

13. What does load(String)::= function do, in System class?
a) Loads dynamic library for a path name
b) Loads all the dynamic libraries
c) Loads all the Number in string format
d) Loads the processor with calculations
Answer: a
Clarification: Only the specified path named dynamic libraries are loaded. All the dynamic libraries can’t be loaded at a time. Hence we use this function for specific libraries.

14. Which is not a System class variable?
a) err
b) out
c) in
d) put
Answer: d
Clarification: Put is not a System class variable. The most general and basic variables are err, out and in. The variables can handle most of the tasks performed in a program.

15. Which package contains the utility classes?
a) java.lang
b) java.utility
c) java.util
d) java.io
Answer: c
Clarification: The package java.util contains all the utility classes. This package also contains generic data structures, date, time etc. These can be used in any java program, you just have to include java.util package.

250+ TOP MCQs on Classes and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Classes”.

1. Which of the following is not type of class?
a) Abstract Class
b) Final Class
c) Start Class
d) String Class
Answer: c
Clarification: 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
Answer: b
Clarification: Classes are pass by reference, and the structures are pass by copy. It doesn’t depend on the 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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 a generic class?
a) Abstract class
b) Final class
c) Template class
d) Efficient Code
Answer: c
Clarification: Template classes are known to be generic classes because those can be used for any data type value and the same class can be used for all the variables of different data types.

6. Size of a class is _____________
a) Sum of the size of all the variables declared inside the class
b) Sum of the size of all the variables along with inherited variables in the class
c) Size of the largest size of variable
d) Classes doesn’t have any size
Answer: d
Clarification: 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
Answer: d
Clarification: 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
Answer: a
Clarification: A friend class can access all the private members of another class, of which it is a 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 the 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
Answer: d
Clarification: 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.
a) True
b) False
Answer: a
Clarification: The class containing main function can be inherited and hence the program can be executed using the derived class names also in java.

11. Which among the following is false, for a 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 the friend keyword
Answer: c
Clarification: Member functions must be declared inside class body, though the definition can be given outside the class body. There is no way to declare the member functions outside 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){} };
Answer: b
Clarification: 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
Answer: b
Clarification: 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
Answer: b
Clarification: 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
Answer: d
Clarification: 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.

250+ TOP MCQs on Data Members and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Data Members”.

1. What is the term used to indicate the variable and constants of a class?
a) Data members
b) Variables of class
c) Data characters
d) Constants
Answer: a
Clarification: The variables inside a class are termed data members of the class. It is not a mandatory rule but variables are used to refer to usual variables used in functions or globally. The term is given because the values stored in those variables represent some kind of data related to class.

2. Data members ________________ (C++)
a) Can be initialized with declaration in classes
b) Can be initialized only with help of constructors
c) Can be initialized either in declaration or by constructor
d) Can’t be initialized
Answer: b
Clarification: The data members are not property of class, those are property of the instances of the class. And the memory for the data members are not reserved until a constructor is called. Hence we use constructors for their initialization after the memory is reserved.

3. Which among the following is true for data members?
a) Private data members can be initialized with declaration in class
b) Static members are initialized in constructors
c) Protected data members can be initialized in class directly
d) Static data members are defined outside class, not in constructor
Answer: d
Clarification: Static members are not property of instances of classes. Those are shared by all the object of classes. Hence those are defined outside the constructor, so as to make them common for all the objects.

4. What should be done for data member to be of user defined structure type?
a) The structure must have been defined before class.
b) The structure must have been defined after the class definition
c) The structure must be predefined
d) The structure type data members can’t be used
Answer: a
Clarification: The structure must have been defined prior to its use. If the structure is not defined, then the memory space will not be allocated for its members. This leads to undefined use of new data types.

5. How many data members can a class contain?
a) 27
b) 255
c) 1024
d) As many as required
Answer: d
Clarification: Any class can have as many data members as required. The only restriction that may arise is when there is not enough memory space. This gives flexibility to define a class with best properties possible.

6. How to access data members of a class?
a) Dot operator
b) Arrow operator
c) Dot or arrow as required
d) Dot, arrow or direct call
Answer: c
Clarification: The data members can never be called directly. Dot operator is used to access the members with help of object of class. Arrow is usually used if pointers are used.

7. To create a pointer to a private data member of a class, outside the class, which among the following is correct?
a) Return the address of the private data member using a member function
b) Access the private member using a pointer outside class
c) Declare the member as pointer inside the class
d) Not possible to create pointer to a private member
Answer: a
Clarification: We can call a public member function and return the address of any private data member. Though the pointer being returned must be defined inside class itself. And the returned address can be stored in a pointer.

8. Which among the following is true for use of setter() and getter() function?
a) Considered best for manipulating data values
b) Considered the only proper way to manipulate the values
c) Considered specially for private members manipulation
d) Considered a red flag, and not recommended for large scale use
Answer: d
Clarification: This concept of getter and setter functions is not acceptable if used too much. This is considered to be inappropriate in OOP perspective. Though it is commonly used, it doesn’t work according to OOP concepts at some higher level of understanding.

9. What is the output of following code?

int n=10;		// global
class A()
{
	private : int n;
	public : int m;
	A()
	{ 
		n=100; m=50;
	}
void disp()
{
	cout<<”n”<<m<<n;
};

a) 1050100
b) 1005010
c) n5010
d) n50100
Answer: d
Clarification: In cout we have specified n as a string to be printed. And m is a variable so its value gets printed. And global variable will not be used since local variable have more preference.

10. The static member functions can only use ________
a) Static data members
b) Private data members
c) Protected data members
d) Constant data members
Answer: a
Clarification: The static member functions can only access static data members. This is because the static member function can’t work with the properties that change object to object. It is mandatory that only the common properties of all the objects be used. And only static data members are common to all as those are property of class.

11. A class can have self-referential data members.
a) True
b) False
Answer: b
Clarification: The data members in a class can never refer to own class type. This is not possible because the data members should have some memory allocated for its object before the self-reference is used, but class must call constructor for that. Hence not possible.

12. What is the keyword used to make data members have same value?
a) static
b) const
c) double
d) abstract
Answer: b
Clarification: The keyword const can be used anywhere to make the variable have same value all the time. This restriction is made to use the same value whenever required. Also, this can restrict accidental changes.

13. Which data members can be inherited but are private to a class?
a) Private
b) Protected
c) Protected and Static
d) Privately inherited
Answer: b
Clarification: Static members inheritance also depends on the type of specifier they have. Only the protected members can be inherited but remain private to class. If static members are defined in private access, they won’t be allowed for inheritance.

14. The arguments passed to member functions by reference are considered as data members of class.
a) True
b) False
Answer: b
Clarification: This is a wrong statement. As only the data defined inside class is considered as its member. But even if a variable is passed by reference it would be the same variable that is outside the class. Hence it can’t be considered class member.

15. Which among the following is not allowed for data member declaration?
a) int a;
b) static int a;
c) abstract a;
d) Boolean a;
Answer: c
Clarification: The abstract keyword in the declaration of data members is not allowed. This is because the abstract keyword features can’t be used with the data members of the class. We can have all other syntax given, but not abstract.

250+ TOP MCQs on Single Level Inheritance and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Single Level Inheritance”.

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
Answer: b
Clarification: 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: d
Clarification: 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
Answer: c
Clarification: 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
Answer: b
Clarification: 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
Answer: a
Clarification: 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
Answer: d
Clarification: 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.

11. What is the output of the 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
Answer: b
Clarification: 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. What is the output of the 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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.