47.2k views
1 vote
Which of the following statements is true? Any data member in an interface is public, static, and final Any data member in an interface is private, static, and final Any method in an interface is public, static, and final Any method in an interface is private, static, and final

User Srdjan
by
7.7k points

1 Answer

1 vote

Final answer:

The true statement is that any data member in an interface is public, static, and final, meaning it is a constant that cannot be changed. Methods are public and can also be default or static, and private methods are possible since Java 9.

Step-by-step explanation:

The statement that is true regarding an interface in Java is: Any data member in an interface is public, static, and final. In Java, when you declare a variable within an interface, it is implicitly public, static, and final, which means it is a constant and cannot be changed. Methods in an interface are also public, but they are not necessarily static or final. With the release of Java 8, interfaces can also have default and static methods, which can have an implementation body. Furthermore, private methods are also allowed in interfaces since Java 9, to allow code reuse within the interface.

User Delita
by
8.1k points