PYTHON Object Oriented Programming MCQs

  1. Which keyword is used to define a class in Python?
    a) class
    b) object
    c) def
    d) struct
    View Answer

    Correct answer: A — class

  2. What will be printed?
    1 python
    2 class Eduinq:
    3 pass
    4 print(type(Eduinq))
    a) <class 'type'>
    b) <class 'class'>
    c) Error
    d) None
    View Answer

    Correct answer: A — <class 'type'>

  3. Which of the following is used to create object of class?
    a) obj = Eduinq()
    b) obj = new Eduinq()
    c) obj = Eduinq.create()
    d) obj = object(Eduinq)
    View Answer

    Correct answer: A — obj = Eduinq()

  4. What is the output of print(isinstance(5,int))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  5. Which of the following is used to define constructor in Python?
    a) init
    b) construct
    c) init()
    d) constructor()
    View Answer

    Correct answer: A — init

  6. What will be printed?
    1 python
    2 class Eduinq:
    3 def __init__(self):
    4 print("Constructor")
    5 Eduinq()
    a) Constructor
    b) Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — Constructor

  7. Which of the following is used to define instance method?
    a) def method(self):
    b) def method():
    c) def method(cls):
    d) def method(obj):
    View Answer

    Correct answer: A — def method(self):

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

    Correct answer: A — Eduinq

  9. Which of the following is used to define class variable?
    a) variable inside class but outside methods
    b) variable inside method
    c) variable inside constructor
    d) variable inside object
    View Answer

    Correct answer: A — variable inside class but outside methods

  10. What will be printed?
    1 python
    2 class Eduinq:
    3 x = 10
    4 print(Eduinq.x)
    a) 10
    b) Error
    c) None
    d) x
    View Answer

    Correct answer: A — 10

  11. Which of the following is used to access instance variable?
    a) self.variable
    b) cls.variable
    c) object.variable
    d) Both A and C
    View Answer

    Correct answer: D — Both A and C

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

    Correct answer: A — True

  13. Which of the following is used to define class method?
    a) @classmethod
    b) @staticmethod
    c) def method(self):
    d) def method():
    View Answer

    Correct answer: A — @classmethod

  14. What will be printed?
    1 python
    2 class Eduinq:
    3 @classmethod
    4 def show(cls):
    5 return "Class Method"
    6 print(Eduinq.show())
    a) Class Method
    b) Error
    c) None
    d) show
    View Answer

    Correct answer: A — Class Method

  15. Which of the following is used to define static method?
    a) @staticmethod
    b) @classmethod
    c) def method(self):
    d) def method(cls):
    View Answer

    Correct answer: A — @staticmethod

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

    Correct answer: A — <class 'main.Eduinq'>

  17. Which of the following is used to inherit class?
    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):

  18. What will be printed?
    1 python
    2 class Parent:
    3 pass
    4 class Child(Parent):
    5 pass
    6 print(issubclass(Child,Parent))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  19. Which of the following is used to check object type?
    a) isinstance(obj,Class)
    b) type(obj)
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  20. What is the output of print(isinstance(Child(),Parent))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  21. Which of the following is used to access class variable?
    a) ClassName.variable
    b) self.variable
    c) object.variable
    d) Both A and C
    View Answer

    Correct answer: A — ClassName.variable

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

    Correct answer: A — 10

  23. Which of the following is used to define private variable?
    a) __variable
    b) _variable
    c) variable
    d) Both A and B
    View Answer

    Correct answer: A — __variable

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

    Correct answer: A — True

  25. Which of the following is used to delete attribute?
    a) del obj.attr
    b) remove obj.attr
    c) delete obj.attr
    d) obj.del(attr)
    View Answer

    Correct answer: A — del obj.attr

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

    Correct answer: A — 5

  27. Which of the following is used to define inheritance?
    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):

  28. What is the output of print(issubclass(Eduinq,object))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  29. Which of the following is used to override 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

  30. 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

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

  32. 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'>

  33. Which of the following is used to define 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):

  34. 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 class C(A,B):
    9 pass
    10 print(C().show())
    a) A
    b) B
    c) Error
    d) None
    View Answer

    Correct answer: A — A

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

    Correct answer: A — ClassName.mro()

  36. What is the output of print(C.mro()) for class C(A,B)?
    a) [C,A,B,object]
    b) [C,B,A,object]
    c) Error
    d) None
    View Answer

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

  37. 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

  38. 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(isinstance(Eduinq,ABC))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  39. 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

  40. What is the output of print(len(dir(object)))?
    a) Number of default methods in object class
    b) Error
    c) None
    d) 0
    View Answer

    Correct answer: A — Number of default methods in object class

  41. Which of the following is used to define encapsulation?
    a) Restricting access to variables
    b) Inheriting classes
    c) Overriding methods
    d) None
    View Answer

    Correct answer: A — Restricting access to variables

  42. What will be printed?
    1 python
    2 class Eduinq:
    3 def __init__(self):
    4 self.__x = 10
    5 obj = Eduinq()
    6 print(hasattr(obj,"__x"))
    a) False
    b) True
    c) Error
    d) None
    View Answer

    Correct answer: A — False

  43. Which of the following is used to define dunder methods?
    a) init, str, repr
    b) init, str, repr
    c) dunder.init, dunder.str
    d) None
    View Answer

    Correct answer: A — init, str, repr

  44. What is the output of print(str(Eduinq())) if Eduinq has str defined?
    a) String returned by str
    b) Error
    c) None
    d) Object address
    View Answer

    Correct answer: A — String returned by str

  45. Which of the following is used to define 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

  46. 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

  47. Which of the following is used to define destructor?
    a) del
    b) destroy
    c) destructor()
    d) del()
    View Answer

    Correct answer: A — del

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

    Correct answer: A — True

  49. Which of the following is used to define class inheritance chain?
    a) issubclass()
    b) isinstance()
    c) type()
    d) id()
    View Answer

    Correct answer: A — issubclass()

  50. What will be printed?
    1 python
    2 class Parent:
    3 pass
    4 class Child(Parent):
    5 pass
    6 print(issubclass(Child,Parent))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

Quick Links to Explore