nerdexam
Oracle

1Z0-808 · Question #18

You are asked to develop a program for a shopping application, and you are given the following information: The application must contain the classes Toy, EduToy, and ConsToy. The Toy class is the…

The correct answer is C. public abstract class Toy { public int calculatePrice(Toy t); public final void printToy(Toy t) { /* code goes here */ } }. https://docs.oracle.com/javase/tutorial/java/land/abstract.html

Advanced Class Design

Question

You are asked to develop a program for a shopping application, and you are given the following information:
  • The application must contain the classes Toy, EduToy, and ConsToy.
  • The Toy class is the superclass of the other two classes.
  • The int calculatePrice (Toy t) method calculates the price of a toy.
  • The void printToy (Toy t) method prints the details of a toy.
Which definition of the Toy class adds a valid layer of abstraction to the class hierarchy?

Options

  • Apublic abstract class Toy { public abstract int calculatePrice(Toy t); public void printToy(Toy t) { /* code goes here */ } }
  • Bpublic abstract class Toy { public int calculatePrice(Toy t); public void printToy(Toy t); }
  • Cpublic abstract class Toy { public int calculatePrice(Toy t); public final void printToy(Toy t) { /* code goes here */ } }
  • Dpublic abstract class Toy { public abstract int calculatePrice(Toy t) { /* code goes here / } public abstract void printToy(Toy t) { / code goes here */ } }

How the community answered

(23 responses)
  • A
    4% (1)
  • B
    9% (2)
  • C
    83% (19)
  • D
    4% (1)

Explanation

https://docs.oracle.com/javase/tutorial/java/land/abstract.html

Topics

#abstract class#abstract methods#class hierarchy#final methods

Community Discussion

No community discussion yet for this question.

Full 1Z0-808 Practice