Question 1 of 25
Hints left: 3
Q1
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)
Q2
What is the purpose of the super() function in object-oriented programming?
Q3
Which principle of OOP is related to creating new classes by extending existing classes?
Q4
What is the primary purpose of a constructor in object-oriented programming?
Q5
What is the purpose of the super() function in object-oriented programming?
Q6
How is polymorphism implemented in object-oriented programming?
Q7
What type of inheritance is illustrated in the following Python code? class A(): pass class B(): pass class C(A,B): pass
Q8
What will be the output of the following Python code? class A: def __init__(self): self._x = 5 class B(A): def display(self): print(self._x) def main(): obj = B() obj.display() main()
Q9
Which of these is a private data field? def Demo: def __init__(self): __a = 1 self.__b = 1 self.__c__ = 1 __d__= 1
Q10
What is the purpose of using encapsulation in object-oriented programming?
Q11
What will be the output of the following Python code? 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()
Q12
What will be the output of the following Python 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)
Q13
What is the main advantage of using abstraction in object-oriented programming?
Q14
Which of the following is the most suitable definition for encapsulation?
Q15
Which of the following statements is true?
Q16
What will be the output of the following Python code? class A: def __init__(self): self.__x = 1 class B(A): def display(self): print(self.__x) def main(): obj = B() obj.display() main()
Q17
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' obj1=A() obj2=B() print(obj1.two(),obj2.two())
Q18
What is the purpose of the __str__ method in Python classes?
Q19
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()
Q20
What is the purpose of the @property decorator in object-oriented programming?
Q21
How does inheritance promote code reusability in object-oriented programming?
Q22
A class in which one or more methods are only implemented to raise an exception is called an abstract class.
Q23
Private members of a class cannot be accessed.
Q24
The purpose of name mangling is to avoid unintentional access of private class members.
Q25
What will be the output of the following Python code? 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()