What will be the output of the following Python code? [code] class Test: def __init__(self): self.x = 0 class Derived_Test(Test):

What will be the output of the following Python code?
Code:
class Test:
    def __init__(self):
        self.x = 0
class Derived_Test(Test):
    def __init__(self):
        self.y = 1
def main():
    b = Derived_Test()
    print(b.x,b.y)
main()
A. 0 1
B. 0 0
C. Error because class B inherits A but variable x isn’t inherited
D. Error because when object is created, argument must be passed like Derived_Test(1)
 
Answer: c
Explanation: Since the invoking method, Test.__init__(self), isn’t present in the derived class, variable x can’t be inherited.
 

Tìm kiếm

Back
Top