- Which of the following is used to achieve inheritance in Python?
View Answer
Correct answer: A — class Child(Parent):
- 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()) View Answer
Correct answer: A — A
- Which of the following is used to achieve multiple inheritance?
View Answer
Correct answer: A — class Child(Parent1,Parent2):
- What is the output of print(issubclass(B,A)) if class B inherits A?
View Answer
Correct answer: A — True
- Which of the following is used to override parent method?
View Answer
Correct answer: A — Define method with same name in child class
- 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()) View Answer
Correct answer: A — Child
- Which of the following is used to access parent method?
View Answer
Correct answer: A — super().method()
- What is the output of print(super(Child,Child()).class)?
View Answer
Correct answer: A — <class 'super'>
- Which of the following is used to define abstract class?
View Answer
Correct answer: D — All of the above
- 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)) View Answer
Correct answer: A — True
- Which of the following is used to define interface in Python?
View Answer
Correct answer: A — Abstract class with abstract methods
- What is the output of print(isinstance(Eduinq(),ABC)) if Eduinq inherits ABC?
View Answer
Correct answer: A — True
- Which of the following is used to define polymorphism?
View Answer
Correct answer: A — Same method name, different behavior
- 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()) View Answer
Correct answer: A — A B
- Which of the following is used to define metaclass?
View Answer
Correct answer: A — class Meta(type):
- What is the output of print(type(type))?
View Answer
Correct answer: A — <class 'type'>
- Which of the following is used to define dunder methods for operator overloading?
View Answer
Correct answer: A — add, sub, mul
- What will be printed?
1 python 2 class Eduinq: 3 def __add__(self,other): 4 return "Added" 5 print(Eduinq()+Eduinq()) View Answer
Correct answer: A — Added
- Which of the following is used to define property in class?
View Answer
Correct answer: A — @property
- What is the output of print(Eduinq().class.name) if Eduinq is a class?
View Answer
Correct answer: A — Eduinq
- Which of the following is used to define property setter?
View Answer
Correct answer: A — @property.setter
- 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) View Answer
Correct answer: A — 10
- Which of the following is used to define property deleter?
View Answer
Correct answer: A — @property.deleter
- What is the output of print(hasattr(Eduinq,"dict"))?
View Answer
Correct answer: A — True
- Which of the following is used to define slots in class?
View Answer
Correct answer: A — slots
- 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) View Answer
Correct answer: A — 10
- Which of the following is used to define multiple constructors?
View Answer
Correct answer: A — @classmethod
- What is the output of print(Eduinq().class.bases) if Eduinq inherits object?
View Answer
Correct answer: A — (<class 'object'>,)
- Which of the following is used to define mixins?
View Answer
Correct answer: A — Class providing additional functionality
- 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()) View Answer
Correct answer: A — Mixin
- Which of the following is used to define metaclass in class definition?
View Answer
Correct answer: A — class MyClass(metaclass=Meta):
- What is the output of print(type(Eduinq)) if Eduinq is defined with metaclass type?
View Answer
Correct answer: A — <class 'type'>
- Which of the following is used to define singleton class?
View Answer
Correct answer: A — Only one instance allowed
- 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) View Answer
Correct answer: A — True
- Which of the following is used to define class decorator?
View Answer
Correct answer: A — @decorator
- What is the output of print(callable(Eduinq)) if Eduinq is a class?
View Answer
Correct answer: A — True
- Which of the following is used to define method chaining?
View Answer
Correct answer: A — Returning self from method
- 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) View Answer
Correct answer: A — 5
- Which of the following is used to define composition?
View Answer
Correct answer: A — Class contains object of another class
- What is the output of print(hasattr(Eduinq(),"class"))?
View Answer
Correct answer: A — True
- Which of the following is used to define delegation?
View Answer
Correct answer: A — Passing responsibility to another object
- 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()) View Answer
Correct answer: A — A
- Which of the following is used to define duck typing?
View Answer
Correct answer: A — Object behavior matters, not type
- What is the output of print(hasattr("Eduinq","iter"))?
View Answer
Correct answer: A — True
- Which of the following is used to define dynamic attribute access?
View Answer
Correct answer: D — All of the above
- 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) View Answer
Correct answer: A — Not Found
- Which of the following is used to define multiple dispatch?
View Answer
Correct answer: A — functools.singledispatch
- What is the output of print(callable(len))?
View Answer
Correct answer: A — True
- Which of the following is used to define method resolution order (MRO)?
View Answer
Correct answer: A — ClassName.mro()
- What will be printed?
1 python 2 class A: pass 3 class B(A): pass 4 print(B.mro()) View Answer
Correct answer: A — [B,A,object]