Bird
0
0

You want to create a class hierarchy where Car and Bike share common features from Vehicle, but each has unique methods. How does inheritance help here?

hard📝 Application Q9 of 15
Java - Inheritance
You want to create a class hierarchy where Car and Bike share common features from Vehicle, but each has unique methods. How does inheritance help here?
AVehicle class holds common features; Car and Bike extend Vehicle and add unique methods
BCar and Bike should extend each other to share features
CVehicle should extend Car and Bike to combine features
DInheritance is not useful; copy code in both classes
Step-by-Step Solution
Solution:
  1. Step 1: Understand class hierarchy design

    Common features belong in Vehicle; Car and Bike specialize Vehicle.
  2. Step 2: Use inheritance to share and extend features

    Car and Bike extend Vehicle to reuse common code and add their own methods.
  3. Final Answer:

    Vehicle class holds common features; Car and Bike extend Vehicle and add unique methods -> Option A
  4. Quick Check:

    Inheritance shares common code, subclasses add specifics [OK]
Quick Trick: Base class for common code; subclasses add unique features [OK]
Common Mistakes:
  • Making subclasses extend each other
  • Making base class extend subclasses
  • Duplicating code instead of inheriting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes