Question from the Java - Fundamentals test

Which of the following statements applies to methods of an interface in Java? (from java 8)

Medium

Which of the following statements applies to methods of an interface in Java? (from java 8)

Author: NathalieStatus: Published(Update)Question passed 909 times
Edit
2
Community Evaluations
developer avatar
Ian
22/05/2023
I answered . The statement "An interface can only contain abstract methods" is true for interfaces in Java. An interface in Java can only declare abstract methods, which means they don't have an implementation. Any class that implements the interface must provide an implementation for these methods. The statement "You can define a method in an interface" is false. In an interface, you can only declare method signatures (abstract methods) without providing an implementation. The statement "The private and protected access modifiers can also be used to declare methods in an interface" is false. In Java, methods in an interface are implicitly public. It is not possible to define private or protected methods within an interface. Therefore, the correct answer is: "An interface can only contain abstract methods."
developer avatar
Auteur anonyme
03/06/2023
Well actually, you can define declare method implementation in interface from Java 8 on thanks to the "default" keyword, so the test is correct
developer avatar
Auteur anonyme
05/06/2023
As Kendall answered you can declare default method from java 8. I will update the question to add then mention of java 8. Thank you both for your comments !
developer avatar
Incorrect answer
Raymond
20/12/2023
By reading Ian's comment, I agree with him and chose the same answer. PS: I am too stingy to spend one correction point to see the solution :)