Quiz on Inheritance in Python
Q.1. Which of the following statements is wrong about inheritance?
Q.2. What is Overriding
Q.3. What is the output of following program?
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()
Q.4. 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?
Q.5. When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword
is used.
Q.6. What type of inheritance is illustrated in the following Python code?
class A():
pass
class B(A):
pass
class C(A):
pass
Q.7. What will be the output of the following Python code?
class A():
def disp(self):
print("A disp()")
class B(A):
pass
obj = B()
obj.disp()
Q.8. The child's __init__() function overrides the inheritance of the parent's __init__() function.
Q.9. Which of the following is not a type of inheritance?
Q.10. Method issubclass() checks if a class is a subclass of another class.
Q.11. What does built-in function help do in context of classes?
Q.12. What will be output for the folllowing 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()
Q.13. What does built-in function type() do in context of classes?
Q.14. What will be the output of the following Python 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())
Q.15. In order to extend a class, the new class should have access to all the data and inner workings of
the parent class.
Instructions:-
- This Quiz is based on Inheritance in Python
- Each correct answer will carry 2 points
- Once an option is selected you cannot select any other, So choose wisely
- Do not refresh the page as it will reset the quiz
- Once the time is up the quiz will automatically get submitted with no of Question responded
- Your total score alongwith your name will be shown after submission of the Quiz
- Wish you ALL THE BEST 👍👍
START
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP