Quiz on Polymorphism in Python
Q.1. Which of the following best describes polymorphism?
Q.2. What is the main motive behind the use of polymorphism?
Q.3. What do you call the languages that support classes but not polymorphism?
Q.4. What type of inheritance is illustrated in the following Python code?
class A:
def __str__(self):
return '1'
class B(A):
def __init__(self):
super().__init__()
class C(B):
def __init__(self):
super().__init__()
def main():
obj1 = B()
obj2 = A()
obj3 = C()
print(obj1, obj2,obj3)
main()
Q.5. What type of inheritance is illustrated in 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'
obj2=B()
print(obj2.two())
Q.6. Which of the following statements is true?
Q.7. What will be the output of the following Python code?
class A:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return 1
def __eq__(self, other):
return self.x * self.y == other.x * other.y
obj1 = A(5, 2)
obj2 = A(2, 5)
print(obj1 == obj2)
Q.8. A class in which one or more methods are only implemented to raise an exception is called an
abstract class.
Q.9. What will be the output of the following Python 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()
Q.10. What is the use of duck typing?
Q.11. Which class/set of classes can illustrate polymorphism in the following code?
abstract class student
{
public : int marks;
calc_grade();
}
class topper:public student
{
public : calc_grade()
{
return 10;
}
};
class average:public student
{
public : calc_grade()
{
return 20;
}
};
class failed{ int marks; };
Q.12. Overriding means changing behaviour of methods of derived class methods in the base class.
Q.13. Which among the following can’t be used for polymorphism?
Q.14. Which among the following can show polymorphism?
Q.15. Which problem may arise if we use abstract class functions for polymorphism?
Instructions:-
- This Quiz is based on Polymorphism 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