Inheritance in Python MCQs Exercise I

Ques 1 Inheritance


Which of the following best describes the inheritance?
1. Inheritance hides the data to implementation.
2. Any parent class can access the member of the child class.
3. A class can access the members of another class just like their own definition.
4. A class cannot access the members of another class just like their own definition.

A 1 only
B 1 and 3 only
C 3 only
D None of these

Ques 2 Inheritance


Which of the following is not a type of Inheritance?

A Single Level Inheritance
B Multi level Ineritance
C Multiple Single Inheritance
D None of there

Ques 3 Inheritance


What is the output of the following Python Code?


class GrandParent:
    def __init__(self):
        print("GrandParent Class Constructor")
class Parent:
    def __init__(self):
        print("Parent Class Constructor")
class Child(GrandParent,Parent):
    def __init__(self):
        print("Chlid Class Constructor")
obj = Child()

A a) GrandParent Class Constructor b) Chlid Class Constructor c)
B 15 15
C GrandParent Class Constructor Parent Class Constructor
D Child Class Constructor
Parent Class Constructor
Grand Parent Class Constructor

Ques 4 Inheritance


What is the output of the following Python Code?


class Parent_Class:
    def __init__(self):
        self.val1 = 10
class Child_Class(Parent_Class):
    def __init__(self):
        self.val2 = 15
obj = Child_Class()
print(obj.val1,obj.val2)

A 10 10
B 15 15
C 15 10
D AttributeError: 'Child_Class' object has no attribute 'val1'

Ques 5 Inheritance


What is the output of the following Python Code?


class Parent_Class:
    def __new__(self):
        self.__init__(self)
        print("Parent Class new invoked")
    def __init__(self):
        print("Parent Class init invoked")
class Child_Class(Parent_Class):
    def __new__(self):
    print("Child Class new invoked")
    def __init__(self):
        print("Child Class init invoked")
ob1 = Child_Class()
ob2 = Parent_Class()

A Child Class init invoked
Parent Class init invoked
B Child Class init invoked
Parent Class new invoked
Parent Class init invoked
C Child Class new invoked
Parent Class new invoked
D Child Class new invoked
Parent Class init invoked
Parent Class new invoked