Oracle
1Z0-819 · Question #121
Given: public interface API { //line 1 public void checkValue(Object value) throws IllegalArgumentException; //line 2 public boolean isValidNumber(Object val) { if (val instanceof Number) { return…
The correct answer is A. Change Line 1 to an abstract class:public abstract class API { E. Change Line 1 to extend java.lang.AutoClosable:public interface API extends AutoCloseable {. See the full explanation below for the reasoning.
Question
Given: public interface API { //line 1
public void checkValue(Object value)
throws IllegalArgumentException; //line 2
public boolean isValidNumber(Object val) {
if (val instanceof Number) {
return true;
}else{
try {
Double.parseDouble(val.toString());
return true;
}catch (NumberFormatException ex) {
return false;
}
}
}
}
Which two changes need to be made to make this class compile? (Choose two.)
Options
- AChange Line 1 to an abstract class:public abstract class API {
- BChange Line 2 access modifier to protected:protected void checkValue(Object value)throws IllegalArgumentException;
- CChange Line 1 to AutoClosable:public API implements AutoCloseable {
- DChange Line 2 to an abstract method:public abstract void checkValue(Object value)throws IllegalArgumentException;
- EChange Line 1 to extend java.lang.AutoClosable:public interface API extends AutoCloseable {
How the community answered
(38 responses)- A74% (28)
- B5% (2)
- C18% (7)
- D3% (1)
Community Discussion
No community discussion yet for this question.