158k views
0 votes
Which of these field declarations are legal within the body of an interface?

(a) Private final static int answer = 42
(b) public static int answer=42
(c) final static answer =42
(d) int answer
(e) No error.

User Imix
by
8.0k points

1 Answer

2 votes

Final answer:

In the body of an interface in Java, only public and public static field declarations are allowed. The correct declaration among the options provided is (b) public static int answer=42.

Step-by-step explanation:

In the body of an interface in Java, only public and public static field declarations are allowed. The correct declaration among the options provided is (b) public static int answer=42.

The keywords private and final cannot be used in the body of an interface, and the keyword static must be used with either public or protected.

So, the answer is (b) public static int answer=42.

User Theraccoonbear
by
8.4k points