Bird
0
0

You want to create a class SmartPhone that has all features of Phone plus new features like camera and GPS. Which is the best way to do this using inheritance?

hard📝 Application Q15 of 15
Java - Inheritance
You want to create a class SmartPhone that has all features of Phone plus new features like camera and GPS. Which is the best way to do this using inheritance?
AMake SmartPhone extend Phone and add new methods
BMake Phone extend SmartPhone and add new methods
CCreate SmartPhone and Phone as separate classes with no relation
DCopy all Phone code into SmartPhone without inheritance
Step-by-Step Solution
Solution:
  1. Step 1: Identify real-world relationship

    A SmartPhone is a type of Phone with extra features, so it should inherit Phone.
  2. Step 2: Apply inheritance correctly

    SmartPhone should extend Phone and add new methods for camera and GPS.
  3. Final Answer:

    Make SmartPhone extend Phone and add new methods -> Option A
  4. Quick Check:

    Subclass adds features to superclass [OK]
Quick Trick: Subclass extends superclass to add features [OK]
Common Mistakes:
  • Reversing inheritance direction
  • Not using inheritance for related classes
  • Copy-pasting code instead of extending

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes