Home / CSE MCQs / Python MCQs :: Discussion

Discussion :: Python MCQs

  1. What is the output of the following piece of code?

    class A():
        def disp(self):
            print("A disp()")
    class B(A):
        pass
    obj = B()
    obj.disp()
  2. A.
    Invalid syntax for inheritance
    B.
    Error because when object is created, argument must be passed
    C.
    Nothing is printed
    D.
    A disp()

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    Class B inherits class A hence the function disp () becomes part of class B's definition. Hence disp() method is properly executed and the line is printed.


Be The First To Comment