1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 95


Given:

Which two changes need to be made to make this class compile? (Choose two.)

Show Answer
Correct Answer: BE

The provided code attempts to define an interface that includes a non-abstract method, `isValueANumber`. However, interfaces in Java cannot contain non-abstract methods unless they are given default or static implementations. Thus, to make this code compile, you need to change the declaration of `API` from an interface to an abstract class, which allows both abstract and concrete methods. Additionally, the `checkValue` method in its current form, being abstract in nature, must be explicitly declared as abstract. This solidifies the changes required: changing `API` to an abstract class `public abstract class API`, and declaring the `checkValue` method as abstract `public abstract void checkValue(Object value) throws IllegalArgumentException;`. These changes ensure that the class contains both abstract and concrete methods, compliant with Java's syntax rules.

Discussion

4 comments
Sign in to comment
StavokOptions: BE
Jul 18, 2023

B AND E ARE CORRECT,TESTED

dillemanOptions: BE
Sep 29, 2023

B and E, tested

d7bb0b2Options: BE
Jan 11, 2024

NEED TWO OPTIONS FOR COMPILATION

ASPushkinOptions: BE
Jun 22, 2024

answer: EB The second method (isValueANumber) cannot be changed and it is a full method. This implies the need for a class in the header (A or E) If the header is E (public abstract class API), then the first method (checkValue) must be abstract or a full (with body). There is just abstract case (B). For the case A the first method (checkValue) must be a full (with body). There is no such a possibility.