Objects Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q21
What is composition in object-oriented programming?
  • A Combining multiple classes into one
  • B A class containing objects of other classes
  • C Inheriting from multiple parents
  • D Converting objects to different types
Answer: Option B
Explanation: Composition is a design principle where a class contains objects of other classes as members.
Q22
What is the purpose of the @property decorator?
  • A To make methods faster
  • B To create read-only properties
  • C To hide methods from other classes
  • D To convert classes to modules
Answer: Option B
Explanation: The @property decorator allows a method to be accessed like an attribute while providing getter functionality.
Q23
What is abstraction in Python?
  • A Making classes abstract
  • B Hiding implementation details
  • C Converting objects to abstract forms
  • D Creating blueprint classes
Answer: Option B
Explanation: Abstraction hides complex implementation details and shows only essential features to the user.
Q24
What are abstract base classes (ABC) in Python?
  • A Classes that are incomplete
  • B Classes that cannot be instantiated directly
  • C Classes with only variables
  • D Classes that are automatically generated
Answer: Option B
Explanation: Abstract base classes cannot be instantiated and require subclasses to implement abstract methods.
Q25
What is the difference between "is" and "==" in Python?
  • A No difference, they are the same
  • B "is" checks identity, "==" checks equality
  • C "is" is faster than "=="
  • D "==" checks identity, "is" checks equality
Answer: Option B
Explanation: "is" checks for identity (same object in memory), while "==" checks for equality (same value).
Questions and Answers for Competitive Exams Various Entrance Test