What does the ‘implements’ keyword do in Java?

Java MCQ: What does the ‘implements’ keyword do in Java?

a) It is used to inherit a class
b) It is used to implement an interface
c) It is used to override a method
d) It is used to define an abstract method

Answer:

b) It is used to implement an interface

Explanation:

The implements keyword in Java is used to indicate that a class is implementing an interface. An interface in Java is a reference type that can contain only abstract methods (until Java 8, which introduced default and static methods in interfaces). A class that implements an interface must provide concrete implementations for all the abstract methods declared in the interface.

When a class implements an interface, it is essentially agreeing to perform the behaviors defined by the interface’s methods. This allows for a form of multiple inheritance, where a class can implement multiple interfaces.

Understanding the implements keyword is crucial for working with interfaces in Java, which are a powerful tool for designing flexible and modular code.

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