Python For OOP: Python MCQs On OOP

Python For OOP. Multiple Choice Questions on OOP concepts with Python coding examples and Questions/Answers.

 

Python For OOP

 

 

What does built-in function help do in context of classes ??

a) Determines the object name of any value
b) Determines the class identifiers of any value
c) Determines class description of any built-in type
d) Determines class description of any user-defined built-in type

 

What will be the output of the code ??

class objects:
def __init__(self):
self.colour = None
self._shape = “Circle”

def display(self, s):
self._shape = s
obj=objects()
print(obj._objects_shape)

a) The program runs fine because name mangling has been properly implemented
b) Error because the member shape is a protected member
c) Error because the proper syntax for name mangling hasn’t been implemented
d) Error because the member shape is a private member

 

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

 

What will be the output of the following Python ??

class A:
def test(self):
print(“test of A called”)
class B(A):
def test(self):
print(“test of B called”)
super().test()
class C(A):
def test(self):
print(“test of C called”)
super().test()
class D(B,C):
def test2(self):
print(“test of D called”)
obj=D()
obj.test()

 

a) test of B called
test of C called
test of A called

b) test of C called
test of B called

c) test of B called
test of C called

d) Error, all the three classes from which D derives has same method test()

 

Python For OOP

 

Which of the following is not a type of inheritance ??

a) Double-level
b) Multi-level
c) Single-level
d) Multiple

 

Which of the following is false about protected class members ??

a) They begin with one underscore
b) They can be accessed by subclasses
c) They can be accessed by name mangling method
d) They can be accessed within a class

 

What will be the output of the following ??

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

 

What will be the output ??

class A:
def test1(self):
print(” test of A called “)
class B(A):
def test(self):
print(” test of B called “)
class C(A):
def test(self):
print(” test of C called “)
class D(B,C):
def test2(self):
print(” test of D called “)
obj=D()
obj.test()

 

a) test of B called
test of C called

b) test of C called
test of B called

 

c) test of B called

 

d) Error, both the classes from which D derives has same method test()

 

Python For OOP

 

What does built-in function type do in context of classes ??

a) Determines the object name of any value
b) Determines the class name of any value
c) Determines class description of any value
d) Determines the file name of any value

 

What will be the output of the ??

class student:
def __init__(self):
self.marks = 97
self.__cgpa = 8.7
def display(self):
print(self.marks)
obj=student()
print(obj._student__cgpa)

 

a) The program runs fine and 8.7 is printed
b) Error because private class members can’t be accessed
c) Error because the proper syntax for name mangling hasn’t been implemented
d) The program runs fine but nothing is printed

 

What will be the output of 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

 

What will be the output of the following Python code ??

class A:
def __init__(self,x=3):
self._x = x
class B(A):
def __init__(self):
super().__init__(5)
def display(self):
print(self._x)
def main():
obj = B()
obj.display()
main()

 

a) 5
b) Error, class member x has two values
c) 3
d) Error, protected class member can’t be accessed in a subclass

 

Python For OOP

 

What will be the output of 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()

a) Error, the syntax of the invoking method is wrong
b) The program runs fine but nothing is printed
c) 1 0
d) 1 2

 

What will be the output ??

class fruits:
def __init__(self):
self.price = 100
self.__bags = 5
def display(self):
print(self.__bags)
obj=fruits()
obj.display()

a) The program has an error because display() is trying to print a private class member
b) The program runs fine but nothing is printed
c) The program runs fine and 5 is printed
d) The program has an error because display() can’t be accessed

 

What will be the output of the 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

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!