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


c is the correct option





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


c is the correct option





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


d is the correct option





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'


d is the correct option





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


d is the correct option