Question 1 of 25
Hints left: 3
Q1
Which principle of OOP allows a class to provide a specific implementation of a method that is already defined in its parent class?
Q2
When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword is used.
Q3
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()
Q4
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()
Q5
What is the purpose of the __del__ method in Python classes?
Q6
What is the main advantage of using polymorphism in object-oriented programming?
Q7
Methods of a class that provide access to private members of the class are called as . . . . . . . . and . . . . . . . .
Q8
All subclasses are a subtype in object-oriented programming.
Q9
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()
Q10
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()
Q11
Which of these is not a fundamental features of OOP?
Q12
Which of the following is false about protected class members?
Q13
What is the main advantage of using encapsulation in object-oriented programming?
Q14
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())
Q15
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)
Q16
Which principle of OOP is associated with the concept of "IS-A" relationship?
Q17
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()
Q18
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)
Q19
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()
Q20
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()
Q21
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()
Q22
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()
Q23
Method issubclass() checks if a class is a subclass of another class.
Q24
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?
Q25
Which of the following statements is true?