Difficulty: Easy
Correct Answer: Through inheritance, a parent class is a more specialised form of the child class.
Explanation:
Introduction / Context:
Inheritance is a core feature of object oriented programming that enables code reuse and the modelling of is a relationships. Understanding the direction of specialisation between parent and child classes is essential. Interviewers often include trick statements that reverse this relationship. This question asks you to identify which statement about inheritance is false.
Given Data / Assumptions:
Concept / Approach:
In an inheritance hierarchy, the superclass represents a more general concept and the subclass represents a more specialised concept. For example, Animal can be a superclass and Dog a subclass. Dog is a more specialised form of Animal, not the other way around. Inheritance allows subclasses to reuse fields and methods from the superclass, reducing duplicate code. The parent class does not become more specialised by inheriting from a child; instead, the child extends the parent.
Step-by-Step Solution:
Step 1: Examine each statement in relation to how inheritance actually works.Step 2: Option A correctly states that inheritance helps minimise duplicate code by sharing common implementations.Step 3: Option B correctly states that a subclass inherits members from its superclass, subject to access modifiers.Step 4: Option D correctly states that inheritance allows reuse of superclass fields and methods.Step 5: Option C claims that the parent is a more specialised form of the child, which reverses the true relationship, so option C is false.
Verification / Alternative check:
Consider a class hierarchy where Vehicle is a superclass and Car is a subclass. Car inherits attributes and behaviours from Vehicle and may add additional properties such as number of doors or engine type. Vehicle does not inherit from Car. Therefore Vehicle is more general, and Car is more specialised. This pattern appears in many domains, confirming that the statement describing the parent as more specialised than the child is incorrect.
Why Other Options Are Wrong:
Option A aligns with the motivation for inheritance, which is to factor out common behaviour into a single place. Option B matches the definition of subclassing, where a subclass gains the accessible members of its superclass. Option D restates the idea of reuse, which is a key benefit of inheritance. These statements are correct and not the ones we seek.
Common Pitfalls:
Some learners confuse inheritance with composition and may misstate the direction of relationships. Others build hierarchies that violate the is a principle, leading to fragile designs. When answering theory questions, always remember that the child is the specialised type and the parent is the more general type. This simple rule helps you spot reversed statements like the one in option C.
Final Answer:
Through inheritance, a parent class is a more specialised form of the child class.
Discussion & Comments