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

5/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 A:
     def __init__(self):
         self.__i = 1
         self.j = 5
 
     def display(self):
         print(self.__i, self.j)
class B(A):
     def __init__(self):
         super().__init__()
         self.__i = 2
         self.j = 7  
c = B()
c.display()

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code?
class A:
    def __repr__(self):
        return "1"
class B(A):
    def __repr__(self):
        return "2"
class C(B):
    def __repr__(self):
        return "3"
o1 = A()
o2 = B()
o3 = C()
print(obj1, obj2, obj3)

Select an option to see the answer and solution.

Overriding means changing behaviour of methods of derived class methods in the base class.

Select an option to see the answer and solution.

How is the concept of abstraction achieved in object-oriented programming?

Select an option to see the answer and solution.

What type of inheritance is illustrated in the following Python code?
class A():
    pass
class B(A):
    pass
class C(B):
    pass

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 display(self):
        return self.__b
 
obj = Demo()
print(obj.__b)

Select an option to see the answer and solution.