Understanding Implements vs. Extends in Java

06 May 2023 Balmiki Mandal 0 Core Java

Implements vs. Extends in Java

When writing Java code, it can be confusing to understand the differences between the keywords Implements and Extends. Knowing when to use each keyword is not only important for writing effective code, but can also help to ensure that you are using the proper Object-Oriented Programming (OOP) principles.

What is the Difference Between Implements and Extends?

The main difference between Implements and Extends is the purpose they serve. Implements is used to implement an interface, while Extends is used to create a class which inherits from a parent class. Thus, Implements is used to add functionality, while Extends is used to create relationships.

Implements in Java

In Java, the Implements keyword is used to declare a class as implementing an interface. An interface is a group of related methods with empty bodies which a class must implement. The class must provide an implementation for each method declared in the interface. Interfaces are commonly used for event handling and to create APIs.

Extends in Java

In contrast, the Extends keyword is used to create a class as a child of another class. This allows the child class to inherit methods and properties from the parent class. Classes can extend only one other class, and a class cannot extend itself. This allows Java code to be more organized and efficient.

Conclusion

Knowing when to use the keywords Implements and Extends is essential for writing effective and efficient Java code. While Implements is used to implement an interface, Extends is used to create a class which inherits from a parent class. Both of these features are necessary for creating robust and well-organized programs.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.