Home / CSE MCQs / Python MCQs :: Discussion

Discussion :: Python MCQs

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

    class Demo:
        def __init__(self):
            self.x = 1
        def change(self):
            self.x = 10
    class Demo_derived(Demo):
        def change(self):
            self.x=self.x+1
            return self.x
    def main():
        obj = Demo_derived()
        print(obj.change())
     
    main()
  2. A.
    11
    B.
    2
    C.
    1
    D.
    An exception is thrown

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    The derived class method change() overrides the base class method.


Be The First To Comment