11. 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()
a) 15
b) 30
c) An exception is thrown
d) 60
12. 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
13. 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)
a) False
b) 1
c) True
d) An exception is thrown
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’
obj2=B()
print(obj2.two())
a) A
b) An exception is thrown
c) A B
d) B
15. 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
16. Which of these is not a fundamental features of OOP?
a) Encapsulation
b) Inheritance
c) Instantiation
d) Polymorphism
17. 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
18. What will be the output of the following Python code?
class Demo:
def __init__(self):
self.a = 1
self.__b = 1
def display(self):
return self.__b
obj = Demo()
print(obj.a)
a) The program has an error because there isn’t any function to return self.a
b) The program has an error because b is private and display(self) is returning a private member
c) The program runs fine and 1 is printed
d) The program has an error as you can’t name a class member using __b
19. What will be the output of the following Python code?
class Demo:
def __init__(self):
self.a = 1
self.__b = 1
def display(self):
return self.__b
obj = Demo()
print(obj.__b)
a) The program has an error because there isn’t any function to return self.a
b) The program has an error because b is private and display(self) is returning a private member
c) The program has an error because b is private and hence can’t be printed
d) The program runs fine and 1 is printed
20. Methods of a class that provide access to private members of the class are called as ______ and ______
a) getters/setters
b) __repr__/__str__
c) user-defined functions/in-built functions
d) __init__/__del__
Page 1 2 3
Python Interview Questions (MCQs)
We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.