Python Inheritance Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q1
What is inheritance in Python?
  • A A mechanism to acquire properties and behaviors of another class
  • B A way to hide data in Python
  • C A method for memory management
  • D A technique for exception handling
Answer: Option A
Explanation: Inheritance allows a class to inherit attributes and methods from another class.
Q2
Which keyword is used for inheritance in Python?
  • A extends
  • B inherits
  • C super
  • D Parent class name in parentheses
Answer: Option D
Explanation: The "class ChildClass(ParentClass):" syntax is used for inheritance in Python.
Q3
What is the parent class of all classes in Python?
  • A Object
  • B Base
  • C Root
  • D Main
Answer: Option A
Explanation: In Python, all classes implicitly inherit from the object class.
Q4
Which method is called when a child class overrides a parent class method?
  • A Parent class method
  • B Child class method
  • C Both methods
  • D Neither method
Answer: Option B
Explanation: The child class method overrides the parent class method when both have the same name.
Q5
What is method overriding in inheritance?
  • A Creating a new method in child class
  • B Redefining a parent class method in child class
  • C Deleting a parent class method
  • D Hiding a parent class method
Answer: Option B
Explanation: Method overriding allows a child class to provide a specific implementation of a method that is already defined in its parent class.
Q6
How can you call a parent class method from a child class?
  • A Using parent()
  • B Using super()
  • C Using base()
  • D Using self.parent
Answer: Option B
Explanation: The super() function is used to call methods from the parent class in the child class.
Q7
What is multiple inheritance in Python?
  • A A class having multiple methods
  • B A class inheriting from multiple parent classes
  • C A class with multiple child classes
  • D A class with multiple constructors
Answer: Option B
Explanation: Multiple inheritance allows a class to inherit from more than one parent class.
Q8
What is the purpose of the __init__ method in inheritance?
  • A To initialize object attributes
  • B To destroy the object
  • C To create class variables
  • D To import modules
Answer: Option A
Explanation: The __init__ method is called when an object is created and can be overridden in child classes.
Q9
What is hierarchical inheritance?
  • A One parent, one child
  • B Multiple parents, one child
  • C One parent, multiple children
  • D Multiple levels of inheritance
Answer: Option C
Explanation: Hierarchical inheritance occurs when multiple child classes inherit from a single parent class.
Q10
What is multilevel inheritance?
  • A Multiple inheritance levels
  • B Inheritance across multiple files
  • C A chain of inheritance
  • D All of the above
Answer: Option C
Explanation: Multilevel inheritance occurs when a child class inherits from a parent class, which itself inherits from another class.
Questions and Answers for Competitive Exams Various Entrance Test