Objects Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
What does the __del__ method do?
  • A Deletes a class
  • B Destructor - called when object is destroyed
  • C Deletes a variable
  • D Delays object creation
Answer: Option B
Explanation: The __del__ method is called when an object is about to be destroyed.
Q12
What is method overriding in Python?
  • A Creating multiple methods with same name in same class
  • B Redefining a parent class method in child class
  • C Hiding methods from other classes
  • D Converting methods to properties
Answer: Option B
Explanation: Method overriding allows a subclass to provide a specific implementation of a method that is already defined in its parent class.
Q13
How do you make a method private in Python?
  • A Using private keyword
  • B Prefix with double underscores
  • C Using @private decorator
  • D Prefix with single underscore
Answer: Option B
Explanation: Private methods are indicated by prefixing the method name with double underscores.
Q14
What is the super() function used for?
  • A To create super classes
  • B To call parent class methods
  • C To make classes faster
  • D To override multiple methods
Answer: Option B
Explanation: The super() function is used to call methods from the parent class.
Q15
What are properties in Python classes?
  • A Variables that can only be read
  • B Attributes with getter/setter methods
  • C Methods that return values
  • D Class-level constants
Answer: Option B
Explanation: Properties allow you to use getter and setter methods while accessing them like regular attributes.
Q16
What is multiple inheritance in Python?
  • A A class with multiple methods
  • B A class inheriting from multiple parents
  • C Multiple instances of same class
  • D A class with multiple constructors
Answer: Option B
Explanation: Multiple inheritance allows a class to inherit from more than one parent class.
Q17
What is the Method Resolution Order (MRO) in Python?
  • A Order of method execution
  • B Order in which base classes are searched for methods
  • C Order of method parameters
  • D Order of object destruction
Answer: Option B
Explanation: MRO determines the order in which base classes are searched when looking for a method.
Q18
What is the difference between __str__ and __repr__?
  • A No difference, they are the same
  • B __str__ for users, __repr__ for developers
  • C __str__ is faster than __repr__
  • D __repr__ is only for numbers
Answer: Option B
Explanation: __str__ is for end-user representation, while __repr__ is for developer representation and should be unambiguous.
Q19
What are class methods in Python?
  • A Methods that only work with class variables
  • B Methods bound to the class, not instance
  • C Methods that cannot be overridden
  • D Methods that are automatically called
Answer: Option B
Explanation: Class methods are bound to the class rather than instances and can modify class state.
Q20
What are static methods in Python?
  • A Methods that cannot be changed
  • B Methods that don't take self or cls
  • C Methods that are fastest
  • D Methods that only work with instances
Answer: Option B
Explanation: Static methods don't have access to the class or instance and behave like regular functions but belong to the class namespace.
Questions and Answers for Competitive Exams Various Entrance Test