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 get(self): return self.__b obj = Demo() print(obj.get())
Q2
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()
Q3
Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write?
Q4
What will be the output of the following Python code? class Test: def __init__(self): self.x = 0 class Derived_Test(Test): def __init__(self): self.y = 1 def main(): b = Derived_Test() print(b.x,b.y) main()
Q5
What is the purpose of the __del__ method in Python classes?
Q6
Method issubclass() checks if a class is a subclass of another class.
Q7
When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword is used.
Q8
What is the main advantage of using polymorphism in object-oriented programming?
Q9
Methods of a class that provide access to private members of the class are called as . . . . . . . . and . . . . . . . .
Q10
Which of these is not a fundamental features of OOP?
Q11
Which principle of OOP allows a class to provide a specific implementation of a method that is already defined in its parent class?
Q12
Which of the following is false about protected class members?
Q13
Which of the following statements is true?
Q14
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)
Q15
What will be the output of the following Python code? class Demo: def __init__(self): self.a = 1 self.__b = 1 def get(self): return self.__b obj = Demo() obj.a=45 print(obj.a)
Q16
What will be the output of the following Python code? class fruits: def __init__(self): self.price = 100 self.__bags = 5 def display(self): print(self.__bags) obj=fruits() obj.display()
Q17
Which principle of OOP is associated with the concept of "IS-A" relationship?
Q18
All subclasses are a subtype in object-oriented programming.
Q19
What will be the output of the following Python code? class Test: def __init__(self): self.x = 0 class Derived_Test(Test): def __init__(self): Test.__init__(self) self.y = 1 def main(): b = Derived_Test() print(b.x,b.y) main()
Q20
What will be the output of the following Python code? class A(): def disp(self): print("A disp()") class B(A): pass obj = B() obj.disp()
Q21
What is the main advantage of using encapsulation in object-oriented programming?
Q22
What will be the output of the following Python code? class A: def __init__(self): self.multiply(15) print(self.i) def multiply(self, i): self.i = 4 * i; class B(A): def __init__(self): super().__init__() def multiply(self, i): self.i = 2 * i; obj = B()
Q23
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()
Q24
What will be the output of the following Python code? class Demo: def __new__(self): self.__init__(self) print("Demo's __new__() invoked") def __init__(self): print("Demo's __init__() invoked") class Derived_Demo(Demo): def __new__(self): print("Derived_Demo's __new__() invoked") def __init__(self): print("Derived_Demo's __init__() invoked") def main(): obj1 = Derived_Demo() obj2 = Demo() main()
Q25
What will be the output of the following Python 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()