What Will Be The Output Of The Following Python Codep Pre #1097
What will be the output of the following Python code?</p> <pre><code class="language-python"> class Demo: def __new__(self): self.__init__(self) print("Demo's __new__() invoked") def __init__(self): print("Demo's __init__() invoked") class Derived_Demo(Demo): def __new__(self): print("Derived_Demo's __new__() invoked") def __init__(self): print("Derived_Demo's __init__() invoked") def main(): obj1 = Derived_Demo() obj2 = Demo() main() </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs109 Python. It can also be found in gs gs109 Python OOPs - Python Inheritance - Quiz No.1.
What will be the output of the following Python code?
class Demo: def __new__(self): self.__init__(self) print("Demo's __new__() invoked") def __init__(self): print("Demo's __init__() invoked") class Derived_Demo(Demo): def __new__(self): print("Derived_Demo's __new__() invoked") def __init__(self): print("Derived_Demo's __init__() invoked") def main(): obj1 = Derived_Demo() obj2 = Demo() main()
Derived_Demo’s __init__() invoked Derived_Demo's __new__() invoked Demo's __init__() invoked Demo's __new__() invoked
Derived_Demo's __new__() invoked Demo's __init__() invoked Demo's __new__() invoked
Derived_Demo's __new__() invoked Demo's __new__() invoked
Derived_Demo’s __init__() invoked Demo's __init__() invoked