Oracle Certified Professional Java Se 11 Developer · Free Practice Question Hard

Question 10

Question ID: UKOCP29082


Given code of Fast annotation:


And code of RoadRunner.java file:


RoadRunner.java causes compilation error.

Which of the following can replace /*INSERT*/, such that given codes compile successfully?

  • A

    String name();

  • B

    String name() default "20MPH";

  • C

    String value();

  • D

    CharSequence value() default "15MPH";

Reveal correct answer

Correct answer: C

Explanation

UKOCP29082:

You are not supposed to make any changes in RoadRunner.java file.

For @Fast("15MPH") to compile, name of the attribute is not used, hence name of the attribute must be 'value'.

Let's check all the options:

String name();

✗  Name of the attribute is 'name' and not 'value'.


String name() default "20MPH";

✗  Name of the attribute is 'name' and not 'value'.


String value();

✓  Name of the attribute is 'value'.


CharSequence value() default "15MPH";

✗  CharSequence is not a valid attribute type.

Type of attribute could be of following:

primitive, String, java.lang.Class, Enum, Annotation, an array of all the previous type.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need