PYTHON Advanced Object Oriented Programming MCQs

  1. Which of the following is used to achieve inheritance in Python?
    a) class Child(Parent):
    b) class Child extends Parent:
    c) class Child inherits Parent:
    d) class Child: Parent
    View Answer

    Correct answer: A — class Child(Parent):

  2. What will be printed?
    1 python
    2 class A:
    3 def show(self):
    4 return "A"
    5 class B(A):
    6 pass
    7 print(B().show())
    a) A
    b) B
    c) Error
    d) None
    View Answer

    Correct answer: A — A

  3. Which of the following is used to achieve multiple inheritance?
    a) class Child(Parent1,Parent2):
    b) class Child extends Parent1,Parent2:
    c) class Child inherits Parent1,Parent2:
    d) class Child: Parent1,Parent2
    View Answer

    Correct answer: A — class Child(Parent1,Parent2):

  4. What is the output of print(issubclass(B,A)) if class B inherits A?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  5. Which of the following is used to override parent method?
    a) Define method with same name in child class
    b) Define method with different name in child class
    c) Define method with same name in parent class
    d) None
    View Answer

    Correct answer: A — Define method with same name in child class

  6. What will be printed?
    1 python
    2 class Parent:
    3 def show(self):
    4 return "Parent"
    5 class Child(Parent):
    6 def show(self):
    7 return "Child"
    8 print(Child().show())
    a) Child
    b) Parent
    c) Error
    d) None
    View Answer

    Correct answer: A — Child

  7. Which of the following is used to access parent method?
    a) super().method()
    b) parent.method()
    c) base.method()
    d) object.method()
    View Answer

    Correct answer: A — super().method()

  8. What is the output of print(super(Child,Child()).class)?
    a) <class 'super'>
    b) <class 'Child'>
    c) Error
    d) None
    View Answer

    Correct answer: A — <class 'super'>

  9. Which of the following is used to define abstract class?
    a) from abc import ABC
    b) class MyClass(ABC):
    c) @abstractmethod
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  10. What will be printed?
    1 python
    2 from abc import ABC,abstractmethod
    3 class Eduinq(ABC):
    4 @abstractmethod
    5 def show(self):
    6 pass
    7 print(issubclass(Eduinq,ABC))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  11. Which of the following is used to define interface in Python?
    a) Abstract class with abstract methods
    b) Concrete class
    c) Module
    d) None
    View Answer

    Correct answer: A — Abstract class with abstract methods

  12. What is the output of print(isinstance(Eduinq(),ABC)) if Eduinq inherits ABC?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  13. Which of the following is used to define polymorphism?
    a) Same method name, different behavior
    b) Different method name, same behavior
    c) Same method name, same behavior
    d) None
    View Answer

    Correct answer: A — Same method name, different behavior

  14. What will be printed?
    1 python
    2 class A:
    3 def show(self):
    4 return "A"
    5 class B:
    6 def show(self):
    7 return "B"
    8 for obj in (A(),B()):
    9 print(obj.show())
    a) A B
    b) B A
    c) Error
    d) None
    View Answer

    Correct answer: A — A B

  15. Which of the following is used to define metaclass?
    a) class Meta(type):
    b) class Meta(object):
    c) class Meta:
    d) None
    View Answer

    Correct answer: A — class Meta(type):

  16. What is the output of print(type(type))?
    a) <class 'type'>
    b) <class 'object'>
    c) Error
    d) None
    View Answer

    Correct answer: A — <class 'type'>

  17. Which of the following is used to define dunder methods for operator overloading?
    a) add, sub, mul
    b) add(), sub(), mul()
    c) operator.add, operator.sub
    d) None
    View Answer

    Correct answer: A — add, sub, mul

  18. What will be printed?
    1 python
    2 class Eduinq:
    3 def __add__(self,other):
    4 return "Added"
    5 print(Eduinq()+Eduinq())
    a) Added
    b) Error
    c) None
    d) EduinqEduinq
    View Answer

    Correct answer: A — Added

  19. Which of the following is used to define property in class?
    a) @property
    b) @classmethod
    c) @staticmethod
    d) None
    View Answer

    Correct answer: A — @property

  20. What is the output of print(Eduinq().class.name) if Eduinq is a class?
    a) Eduinq
    b) class
    c) Error
    d) None
    View Answer

    Correct answer: A — Eduinq

  21. Which of the following is used to define property setter?
    a) @property.setter
    b) @classmethod
    c) @staticmethod
    d) None
    View Answer

    Correct answer: A — @property.setter

  22. What will be printed?
    1 python
    2 class Eduinq:
    3 def __init__(self):
    4 self._x = 10
    5 @property
    6 def x(self):
    7 return self._x
    8 obj = Eduinq()
    9 print(obj.x)
    a) 10
    b) Error
    c) None
    d) x
    View Answer

    Correct answer: A — 10

  23. Which of the following is used to define property deleter?
    a) @property.deleter
    b) @classmethod
    c) @staticmethod
    d) None
    View Answer

    Correct answer: A — @property.deleter

  24. What is the output of print(hasattr(Eduinq,"dict"))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  25. Which of the following is used to define slots in class?
    a) slots
    b) dict
    c) init
    d) class
    View Answer

    Correct answer: A — slots

  26. What will be printed?
    1 python
    2 class Eduinq:
    3 __slots__ = ['x']
    4 def __init__(self):
    5 self.x = 10
    6 obj = Eduinq()
    7 print(obj.x)
    a) 10
    b) Error
    c) None
    d) x
    View Answer

    Correct answer: A — 10

  27. Which of the following is used to define multiple constructors?
    a) @classmethod
    b) @staticmethod
    c) init overloading
    d) None
    View Answer

    Correct answer: A — @classmethod

  28. What is the output of print(Eduinq().class.bases) if Eduinq inherits object?
    a) (<class 'object'>,)
    b) None
    c) Error
    d) Empty
    View Answer

    Correct answer: A — (<class 'object'>,)

  29. Which of the following is used to define mixins?
    a) Class providing additional functionality
    b) Abstract class
    c) Interface
    d) None
    View Answer

    Correct answer: A — Class providing additional functionality

  30. What will be printed?
    1 python
    2 class Mixin:
    3 def mix(self):
    4 return "Mixin"
    5 class Eduinq(Mixin):
    6 pass
    7 print(Eduinq().mix())
    a) Mixin
    b) Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — Mixin

  31. Which of the following is used to define metaclass in class definition?
    a) class MyClass(metaclass=Meta):
    b) class MyClass(Meta):
    c) class MyClass extends Meta:
    d) None
    View Answer

    Correct answer: A — class MyClass(metaclass=Meta):

  32. What is the output of print(type(Eduinq)) if Eduinq is defined with metaclass type?
    a) <class 'type'>
    b) <class 'Eduinq'>
    c) Error
    d) None
    View Answer

    Correct answer: A — <class 'type'>

  33. Which of the following is used to define singleton class?
    a) Only one instance allowed
    b) Multiple instances allowed
    c) Abstract class
    d) None
    View Answer

    Correct answer: A — Only one instance allowed

  34. What will be printed?
    1 python
    2 class Singleton:
    3 _instance = None
    4 def __new__(cls):
    5 if cls._instance is None:
    6 cls._instance = super().__new__(cls)
    7 return cls._instance
    8 a = Singleton()
    9 b = Singleton()
    10 print(a is b)
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  35. Which of the following is used to define class decorator?
    a) @decorator
    b) @classmethod
    c) @staticmethod
    d) None
    View Answer

    Correct answer: A — @decorator

  36. What is the output of print(callable(Eduinq)) if Eduinq is a class?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  37. Which of the following is used to define method chaining?
    a) Returning self from method
    b) Returning object from method
    c) Returning class from method
    d) None
    View Answer

    Correct answer: A — Returning self from method

  38. What will be printed?
    1 python
    2 class Eduinq:
    3 def setx(self,x):
    4 self.x = x
    5 return self
    6 print(Eduinq().setx(5).x)
    a) 5
    b) Error
    c) None
    d) x
    View Answer

    Correct answer: A — 5

  39. Which of the following is used to define composition?
    a) Class contains object of another class
    b) Class inherits another class
    c) Class overrides another class
    d) None
    View Answer

    Correct answer: A — Class contains object of another class

  40. What is the output of print(hasattr(Eduinq(),"class"))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  41. Which of the following is used to define delegation?
    a) Passing responsibility to another object
    b) Inheriting class
    c) Overriding method
    d) None
    View Answer

    Correct answer: A — Passing responsibility to another object

  42. What will be printed?
    1 python
    2 class A:
    3 def show(self):
    4 return "A"
    5 class B:
    6 def __init__(self):
    7 self.a = A()
    8 def show(self):
    9 return self.a.show()
    10 print(B().show())
    a) A
    b) B
    c) Error
    d) None
    View Answer

    Correct answer: A — A

  43. Which of the following is used to define duck typing?
    a) Object behavior matters, not type
    b) Object type matters, not behavior
    c) Both type and behavior matter
    d) None
    View Answer

    Correct answer: A — Object behavior matters, not type

  44. What is the output of print(hasattr("Eduinq","iter"))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  45. Which of the following is used to define dynamic attribute access?
    a) getattr
    b) setattr
    c) delattr
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  46. What will be printed?
    1 python
    2 class Eduinq:
    3 def __getattr__(self,name):
    4 return "Not Found"
    5 obj = Eduinq()
    6 print(obj.x)
    a) Not Found
    b) Error
    c) None
    d) x
    View Answer

    Correct answer: A — Not Found

  47. Which of the following is used to define multiple dispatch?
    a) functools.singledispatch
    b) @staticmethod
    c) @classmethod
    d) None
    View Answer

    Correct answer: A — functools.singledispatch

  48. What is the output of print(callable(len))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  49. Which of the following is used to define method resolution order (MRO)?
    a) ClassName.mro()
    b) ClassName.order()
    c) ClassName.resolve()
    d) ClassName.chain()
    View Answer

    Correct answer: A — ClassName.mro()

  50. What will be printed?
    1 python
    2 class A: pass
    3 class B(A): pass
    4 print(B.mro())
    a) [B,A,object]
    b) [A,B,object]
    c) Error
    d) None
    View Answer

    Correct answer: A — [B,A,object]

Quick Links to Explore