Given:
interface Books {
//insert code here
}
Which fragment, inserted in the Books interface, enables the code to compile?
A.
public abstract String type;
public abstract String getType();
B.
public staticString type;
public abstract String getType();
C.
public String type = “Fiction”;
public static String getType();
D.
public String type = “Fiction”;
public abstract String getType();
The field in a interfact defaults to public static final.
Correct Answer D
D is the correct answer for sure
fields need both be final and static , without static we cannot initialize, because we have no constructors in interfaces.
And methods are public abstract , and cannot be static because interface methods are designed solely for instance specific. without an implementation they are useless.