Given:
public interface ExampleInterface{ }
Which two statements are valid to be written in this interface? (Choose two.)
Given:
public interface ExampleInterface{ }
Which two statements are valid to be written in this interface? (Choose two.)
In a Java interface, it is permissible to declare abstract methods and constants. Abstract methods do not have a body and are meant to be implemented by classes that implement the interface. Therefore, the statements 'public String methodD();' and 'public abstract void methodB();' are valid because they declare abstract methods that do not have a body. Constants in an interface are implicitly public, static, and final, but no such constant is provided in the options. Hence, these two statements are correctly valid in an interface.
answer :AE Interface attributes are by default public, static, final Constants must be set to a value
A. Double c = (Double) i; // Inconvertible types; cannot cast 'java.lang.Integer' to 'java.lang.Double B. Double b = Double.valueOf(i); //Ok C. Double a = i; // Required type: Double - Provided: Integer D. double e = Double.parseDouble(i); // Required type: String - Provided: Integer E. double d= i; //Ok
B is invalid because interface only accepts constant that is marked as static and final
Answer: AE
A & E are correct TESTED
In a Java interface, only abstract methods and constants are allowed. Therefore, the two valid statements that can be written in the ExampleInterface are A. public String methodD(); and E. public abstract void methodB();. Both of these statements declare abstract methods, which is allowed in an interface.