Python Inheritance Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q21
Can we inherit from built-in types like list or dict?
  • A No, never
  • B Yes, always
  • C Only from some built-in types
  • D Only with special permission
Answer: Option B
Explanation: Yes, Python allows inheriting from built-in types to create customized versions.
Q22
What is method overloading in Python?
  • A Multiple methods with same name different parameters
  • B Redefining parent method in child
  • C Creating abstract methods
  • D Hiding methods
Answer: Option A
Explanation: Python doesn't support traditional method overloading, but we can use default arguments or variable arguments.
Q23
What is composition in OOP?
  • A Inheriting from multiple classes
  • B Containing objects of other classes
  • C Method overriding
  • D Class nesting
Answer: Option B
Explanation: Composition is an alternative to inheritance where a class contains objects of other classes.
Q24
When to use inheritance vs composition?
  • A Always use inheritance
  • B Always use composition
  • C Inheritance for is-a, composition for has-a
  • D No difference
Answer: Option C
Explanation: Use inheritance for "is-a" relationships and composition for "has-a" relationships.
Q25
What is the output of: print(issubclass(bool, int))
  • A True
  • B False
  • C Error
  • D None
Answer: Option A
Explanation: In Python, bool is a subclass of int. True and False are instances of bool which is a subclass of int.
Questions and Answers for Competitive Exams Various Entrance Test