Python Programming (2180711) MCQs

MCQs of Classes and Object-Oriented Programming

Showing 31 to 40 out of 45 Questions
31.
Which of the following best describes polymorphism?
(a) Ability of a class to derive members of another class as a part of its own definition
(b) Means of bundling instance variables and methods in order to restrict access to certain class members
(c) Focuses on variables and passing of variables to functions
(d) Allows for objects of different types and behaviour to be treated as the same general type
Answer:

Option (d)

32.
What is the biggest reason for the use of polymorphism?
(a) It allows the programmer to think at a more abstract level
(b) There is less program code to write
(c) The program will have a more elegant design and will be easier to maintain and update
(d) Program code takes up less space
Answer:

Option (c)

33.
What is the use of duck typing?
(a) More restriction on the type values that can be passed to a given method
(b) No restriction on the type values that can be passed to a given method
(c) Less restriction on the type values that can be passed to a given method
(d) Makes the program code smaller
Answer:

Option (c)

34.
A class in which one or more methods are only implemented to raise an exception is called an abstract class.
(a) TRUE
(b) FALSE
Answer:

Option (a)

35.
Overriding means changing behaviour of methods of derived class methods in the base class.
(a) TRUE
(b) FALSE
Answer:

Option (b)

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

Option (d)

37.
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()
(a) Demo’s check Derived’s check
(b) Demo’s check Demo’s check
(c) Derived’s check Demo’s check
(d) Syntax error
Answer:

Option (a)

38.
Which of the following statements is true?
(a) A non-private method in a superclass can be overridden
(b) A subclass method can be overridden by the superclass
(c) A private method in a superclass can be overridden
(d) Overriding isn’t possible in Python
Answer:

Option (a)

39.
Which of these is not a fundamental feature of OOP?
(a) Encapsulation
(b) Inheritance
(c) Instantiation
(d) Polymorphism
Answer:

Option (c)

40.
Which of the following is the most suitable definition for encapsulation?
(a) Ability of a class to derive members of another class as a part of its own definition
(b) Means of bundling instance variables and methods in order to restrict access to certain class members
(c) Focuses on variables and passing of variables to functions
(d) Allows for implementation of elegant software that is well designed and easily modified
Answer:

Option (b)

Showing 31 to 40 out of 45 Questions