Select an option to see the answer and solution.
Concept of Object Oriented Programs in Python
practice.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
87
Questions
2/5
Page
Pick an option on a question to see the right answer and solution.
Select an option to see the answer and solution.
>>> class A:
pass
>>> class B(A):
pass
>>> obj=B()
>>> isinstance(obj,A)Select an option to see the answer and solution.
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()Select an option to see the answer and solution.
Select an option to see the answer and solution.
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()Select an option to see the answer and solution.
class Demo:
def __init__(self):
self.a = 1
self.__b = 1
def display(self):
return self.__b
obj = Demo()
print(obj.a)Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
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()Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
class A:
def one(self):
return self.two()
def two(self):
return 'A'
class B(A):
def two(self):
return 'B'
obj1=A()
obj2=B()
print(obj1.two(),obj2.two())Select an option to see the answer and solution.
class A():
pass
class B():
pass
class C(A,B):
passSelect an option to see the answer and solution.
class A:
def __init__(self):
self._x = 5
class B(A):
def display(self):
print(self._x)
def main():
obj = B()
obj.display()
main()Select an option to see the answer and solution.
class objects:
def __init__(self):
self.colour = None
self._shape = "Circle"
def display(self, s):
self._shape = s
obj=objects()
print(obj._objects_shape)Select an option to see the answer and solution.
class A:
def __init__(self):
self.__x = 1
class B(A):
def display(self):
print(self.__x)
def main():
obj = B()
obj.display()
main()Select an option to see the answer and solution.
class A:
def __init__(self,x):
self.x = x
def count(self,x):
self.x = self.x+1
class B(A):
def __init__(self, y=0):
A.__init__(self, 3)
self.y = y
def count(self):
self.y += 1
def main():
obj = B()
obj.count()
print(obj.x, obj.y)
main()Select an option to see the answer and solution.