MCQ Set 2
MCQ Set 2
- A) A class is defined
- B) An object is created
- C) A method is called
- D) A variable is created
- A) Global namespace
- B) Built-in namespace
- C) Local namespace
- D) Module namespace
- A) varName
- B) varName
- C) public varName
- D) _varName
Answer: B) varName
Answer: B) Hiding implementation details and showing only the necessary features
- A) Defining variables
- B) Defining lists
- C) Creating a new class
- D) Writing comments
- A) MyClass
- B) 1stClass
- C) ClassOne
- D) _HiddenClass
Answer: B) 1stClass
- A) Static methods
- B) Instance methods
- C) Class methods
- D) Functions outside classes
- A) By using @static
- B) By using @class
- C) By using @classmethod
- D) By using @instancemethod
Q16: What parameter is typically used in a class method to represent the class?
- A) self
- B) cls
- C) class
- D) instance
Answer: B) cls
Q17: Which of the following statements about static methods is true?
Q18: How can you access the attributes of one class in another class?
- D) Only methods
Q2: What will happen if you try to access an attribute that doesn't exist in the class?
Q3: Which of the following methods is called automatically when you try to print an object?
- A) __str__()
- B) __init__()
- C) __new__()
- D) __repr__()
Answer: A) __str__()
Q4: Which access modifier would you use to define an attribute accessible only within the class?
- A) Protected
- B) Public
- C) Private
- D) Static
Answer: C) Private
Q6: If a class has the method __call__() , the object of that class can be:
- B) Printed directly
- C) Used in a loop
Q7: If you try to modify a read-only property of a class, which error is raised?
- A) TypeError
- B) ValueError
- C) AttributeError
- D) SyntaxError
Answer: C) AttributeError
- B) Overriding is defining a new method with the same name in the child class
Answer: B) Overriding is defining a new method with the same name in the child class
Q9: In case of multiple inheritance, which algorithm does Python use to resolve method names?
- A) Depth-first search
- C) Breadth-first search
- B) Access a property
- C) Delete a property
- A) @property
- B) @property_name.setter
- C) @setter
- D) @property_name.getter
Answer: B) @property_name.setter
Q12: In Python, if a property’s getter method is defined but no setter is defined, the property is:
- A) Read-write
- B) Write-only
- C) Read-only
Answer: C) Read-only
Q13: When two methods in a class have the same name but different parameters, it is called:
- A) Overloading
- B) Overriding
- C) Abstracting
- D) Encapsulating
Answer: A) Overloading
Q14: Python does not support method overloading directly, but similar behavior can be achieved using:
- A) Default arguments
- B) @staticmethod
- C) Abstract methods
- A) Single Inheritance
- B) Multiple Inheritance
- C) Linear Inheritance
- D) Multilevel Inheritance
- A) Derived class
- B) Parent class
- C) Base class
- D) Abstract class
Q18: Which inheritance type allows a class to inherit from multiple parent classes?
- A) Single Inheritance
- B) Multiple Inheritance
- C) Hierarchical Inheritance
- D) Multilevel Inheritance
- A) Multiple Inheritance
- B) Single Inheritance
- C) Hierarchical Inheritance
- D) Hybrid Inheritance
Q20: In Python, which built-in function returns the base classes of a class?
- A) super()
- B) base()
- C) __bases__
- D) mro()
Answer: C) __bases__
- A) __init__()
- B) super()
- C) base()
- D) parent()
Answer: B) super()
- C) Itself
- A) Base class
- B) Parent class
- C) Derived class
- A) class A(B):
Q29: In single inheritance, which class does not inherit any features?
- A) Base class
- B) Derived class
- C) Child class
- C) No base classes
- A) It is always efficient.
- C) Reduced reusability.
- D) Limited
access to attributes.
Q32: Which Python feature resolves the order of calling methods in multiple inheritance?
- A) Encapsulation
- B) Polymorphism
- C) MRO
Answer: C) MRO
Q33: In multiple inheritance, the method resolution order (MRO) is determined using:
- A) Depth-first search
- C) Breadth-first search
- D) FCFS rule
Q35: Which inheritance allows a class to inherit attributes of more than one class?
- A) Multiple Inheritance
- B) Hybrid Inheritance
- C) Single Inheritance
- D) None
- A) inherit
- B) extends
- C) inherits
- D) None
- A) super()
- B) mro()
- C) __dict__
- D) isinstance()
Answer: B) mro()
- D) To overload methods
- A) Private method
- B) Public method
- C) Encapsulated method
- A) class Child(Parent):
- B) class Parent->Child:
- D) Parent: Child
- A) super().__init__()
- B) base()
- C) super()
- D) super.method()
Answer: A) super().__init__()
- A) Setter
- B) Property
- D) staticmethod
Answer: B) Property
- A) Using encapsulation