Which of the following is true about interfaces in Java?

Java MCQ: Which of the following is true about interfaces in Java?

a) Interfaces can contain default methods
b) Interfaces can contain abstract methods
c) Interfaces cannot have instance variables
d) All of the above

Answer:

d) All of the above

Explanation:

In Java, interfaces are used to define a contract that classes can implement. Interfaces can contain abstract methods, which must be implemented by any class that implements the interface. Since Java 8, interfaces can also contain default methods, which provide a default implementation that classes can use or override.

Additionally, interfaces cannot have instance variables. They can only have static final variables, which are constants.

Understanding the structure and capabilities of interfaces is essential for designing flexible and reusable Java code, as interfaces allow multiple classes to share a common behavior.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top