Bird
0
0

Which OOP feature helps you write a base class Vehicle and create specific classes like Car and Bike that share common code but also have their own details?

hard📝 Application Q15 of 15
Java - Object-Oriented Programming Concepts
You want to reuse code for different types of vehicles in Java. Which OOP feature helps you write a base class Vehicle and create specific classes like Car and Bike that share common code but also have their own details?
AInheritance to extend Vehicle class for Car and Bike
BEncapsulation to hide Vehicle data from Car and Bike
CPolymorphism to create unrelated classes Car and Bike
DAbstraction to write all code only in Vehicle class
Step-by-Step Solution
Solution:
  1. Step 1: Understand code reuse in OOP

    Inheritance allows new classes to reuse code from a base class and add their own features.
  2. Step 2: Match feature to scenario

    Vehicle is base class; Car and Bike extend it to share common code and add details.
  3. Final Answer:

    Inheritance to extend Vehicle class for Car and Bike -> Option A
  4. Quick Check:

    Code reuse via inheritance = B [OK]
Quick Trick: Use inheritance to share and extend code [OK]
Common Mistakes:
  • Confusing encapsulation with code reuse
  • Thinking polymorphism creates unrelated classes
  • Believing abstraction means no subclass code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes