Vidyalelo
Python · all questions

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

4/5

Page

Pick an option on a question to see the right answer and solution.

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)

Select an option to see the answer and solution.

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()

Select an option to see the answer and solution.

Method issubclass() checks if a class is a subclass of another class.

Select an option to see the answer and solution.

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())

Select an option to see the answer and solution.

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()

Select an option to see the answer and solution.

Methods of a class that provide access to private members of the class are called as . . . . . . . . and . . . . . . . .

Select an option to see the answer and solution.

Which principle of OOP is associated with the concept of "IS-A" relationship?

Select an option to see the answer and solution.

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()

Select an option to see the answer and solution.

Which of the following statements is true?

Select an option to see the answer and solution.

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()

Select an option to see the answer and solution.

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?

Select an option to see the answer and solution.

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()

Select an option to see the answer and solution.

What is the purpose of the __del__ method in Python classes?

Select an option to see the answer and solution.

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()

Select an option to see the answer and solution.

When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword is used.

Select an option to see the answer and solution.

What is the main advantage of using polymorphism in object-oriented programming?

Select an option to see the answer and solution.

What is the benefit of using polymorphism in object-oriented programming?

Select an option to see the answer and solution.

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'
obj2=B()
print(obj2.two())

Select an option to see the answer and solution.

What will be the output of the following Python code?
class student:
    def __init__(self):
        self.marks = 97
        self.__cgpa = 8.7
    def display(self):
        print(self.marks)
obj=student()
print(obj._student__cgpa)

Select an option to see the answer and solution.

What will be the output of the following Python code?
class A:
    def test1(self):
        print(" test of A called ")
class B(A):
    def test(self):
        print(" test of B called ")
class C(A):
    def test(self):
        print(" test of C called ")
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.