QuestionQ188

Working with Inheritance

You are asked to develop a program for a shopping application and are given the following information:

  • The application must include the classes Toy, EduToy, and ConsToy. Toy is the superclass of the other two classes.
  • The int calculatePrice(Toy t) method calculates a toy's price.
  • The void printToy(Toy t) method prints a toy's details.

Which definition of the Toy class adds a valid abstraction layer to the class hierarchy?

  • A
  • B
  • C
  • D
Explanation

An abstract Toy class can require each concrete toy subtype to implement its own price calculation through an abstract calculatePrice method, while supplying a concrete printToy method that subclasses inherit. This establishes a common superclass contract and allows type-specific pricing behavior.

Community Discussion

No comments yet. Be the first to start the discussion!