Site icon i2tutorials

Python-Polymorphism-Quiz

This Quiz contains totally 10 Questions each carry 1 point for you.

1. Which of the following best describes polymorphism?
Focuses on variables and passing of variables to functions
Allows for objects of different types and behaviour to be treated as the same general type
All the above
None of the above

Correct!

Wrong!

2. What is the main motive behind the use of polymorphism?
It lets the developer to think at a more abstract level
There is less program code to write
The program can have more elegant design, and will be easier to maintain and update
Program code takes up less space

Correct!

Wrong!

3. 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'
obj2=B()
print(obj2.two())
A
An exception is thrown
A B
B

Correct!

Wrong!

4. What will be the output of the following Python code?
class A:
    def __init__(self):
       self.multiply(15)
    def multiply(self, i):
        self.i = 4 * i;
class B(A):
    def __init__(self):
       super().__init__()
        print(self.i)
     def multiply(self, i):
       self.i = 2 * i;
obj = B()
15
30
An exception is thrown
60

Correct!

Wrong!

5. What will be the output of the following Python code?
class Demo:
   def check(self):
        return " Demo's check "
      def display(self):
        print(self.check())
class Demo_Derived(Demo):
    def check(self):
       return " Derived's check "
Demo().display()
Demo_Derived().display()
Demo’s check Derived’s check
Demo’s check Demo’s check
Derived’s check Demo’s check
Syntax error

Correct!

Wrong!

6. What will be the output of the following Python code?
class A:
   def __repr__(self):
       return "1"
class B(A):
   def __repr__(self):
       return "2"
class C(B):
   def __repr__(self):
       return "3"
o1 = A()
o2 = B()
o3 = C()
print(o1, o2, o3)
1 1 1
1 2 3
‘1’ ‘1’ ‘1’
An exception is thrown

Correct!

Wrong!

7. Overriding is nothing but changing behaviour of methods of derived class methods in the base class.
True
False

Correct!

Wrong!

8. A class in which one or more methods are employed to raise an exception is so-called as an abstract class.
True
False

Correct!

Wrong!

9. What is the use of duck typing?
More constraint on the type values that are passed to a given method
No constraint on the type values that are passed to a given method
Less constraint on the type values that are passed to a given method
Makes the program code smaller

Correct!

Wrong!

10. 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)
False
1
True
An exception is thrown

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

Python-Polymorphism-Quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...

Exit mobile version