8. What is the output of the following piece of 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()
Correct Answer is : Error because class B inherits A but variable x isn’t inherited
9. 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()
Correct Answer is : A disp()
10. All subclasses are a subtype in object-oriented programming. Is the statement true or false?
Correct Answer is : FALSE
11. When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword is used. Is the statement true or false?
Correct Answer is : FALSE
12. Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write?
Correct Answer is : A.__init__(self)
13. What is the output of the following piece of code?
class Test:
def __init__(self):
self.x = 0
class Derived_Test(Test):
def __init__(self):
Test.__init__(self)
self.y = 1
def main():
b = Derived_Test()
print(b.x,b.y)
main()
Correct Answer is : 0 1
14. What is the output of the following piece of code?
class A:
def __init__(self, x= 1):
self.x = x
class der(A):
def __init__(self,y = 2):
super().__init__()
self.y = y
def main():
obj = der()
print(obj.x, obj.y)
main()
Correct Answer is : 45293
15. What does built-in function type do in context of classes?
Correct Answer is : Determines the class name of any value
16. Which of the following is not a type of inheritance?
Correct Answer is : Double-level
17. What does built-in function help do in context of classes?
Correct Answer is : Determines class description of any built-in type
18. What is the output of the following piece of code?
class A:
def one(self):
return self.two()
def two(self):
return 'A'
class B(A):
def two(self):
return 'B'
obj1=A()
obj2=B()
print(obj1.two(),obj2.two())
Correct Answer is : A B
19. What type of inheritance is illustrated in the following piece of code?
class A():
pass
class B():
pass
class C(A,B):
pass
Correct Answer is : Multiple inheritance
20. What type of inheritance is illustrated in the following piece of code?
class A():
pass
class B(A):
pass
class C(B):
pass