Classes Questions and Answers
Practice ModeShowing 10 of 25 questions
Q11
What is the difference between class and instance variables?
Answer: Option C
Explanation: Class variables are shared among all instances, while instance variables are unique to each instance.
Q12
How do you create a static method in Python?
Answer: Option A
Explanation: Static methods are created using the @staticmethod decorator and don't take self or cls parameters.
Q13
What is a class method in Python?
Answer: Option B
Explanation: Class methods take cls as first parameter and can access and modify class state.
Q14
What is the purpose of the __str__ method?
Answer: Option A
Explanation: The __str__ method returns a string representation of the object, used by print() and str().
Q15
What is multiple inheritance in Python?
Answer: Option B
Explanation: Multiple inheritance allows a class to inherit from more than one parent class.
Q16
What is an abstract class in Python?
Answer: Option C
Explanation: Abstract classes cannot be instantiated and require subclasses to implement abstract methods.
Q17
How do you create a property in Python?
Answer: Option B
Explanation: Properties are created using the @property decorator to define getter methods.
Q18
What is method overloading in Python?
Answer: Option A
Explanation: Python doesn't support traditional method overloading, but you can use default arguments or variable arguments to achieve similar functionality.
Q19
What is the MRO (Method Resolution Order) in Python?
Answer: Option B
Explanation: MRO determines the order in which base classes are searched when looking for a method.
Q20
What is a destructor method in Python?
Answer: Option B
Explanation: The __del__ method is called when an object is about to be destroyed.