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