Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming / Difference Between Implements and Extends

Difference Between Implements and Extends

May 7, 2011 Posted by Indika

Implements vs Extends

Implements and Extends are two keywords found in Java programming language that provides a means of transferring added functionality to a new class. Implements keyword is used explicitly for implementing an interface, while Extends keyword is used for inheriting from a (super) class. Please note that the concepts of inheritance and interfaces are present in most of the other object oriented programming languages like C# and VB.NET, but they offer different syntax or keywords for applying those concepts. This article only focuses on Implements and Extends keywords defined in Java.

Extends

Extends keyword is used to implement the concept of inheritance in Java programming language. Inheritance essentially provides code reuse by allowing extending properties and behavior of an existing class by a newly defined class. When a new subclass (or derived class) extends a super class (or parent class) that subclass will inherit all attributes and methods of the super class. The subclass can optionally override the behavior (provide new or extended functionality to methods) inherited from the parent class. A subclass cannot extend multiple super classes in Java. Therefore, you cannot use extends for multiple inheritance. In order to have multiple inheritance, you need to use interfaces as explained below.

Implements

Implements keyword in Java programming language is used for implementing an interface by a class. An interface in Java is an abstract type that is used to specify a contract that should be implemented by classes, which implement that interface. Usually an interface will only contain method signatures and constant declarations. Any interface that implements a particular interface should implement all methods defined in the interface, or should be declared as an abstract class. In Java, the type of an object reference can be defined as an interface type. But that object must either be null or should hold an object of a class, which implements that particular interface. Using Implements keyword in Java, you can implement multiple interfaces to a single class. An Interface cannot implement another interface. However an interface can extend a class.

Difference between Implements and Extends

Although, Implements and Extends are two keywords that provide a mechanism to inherit attributes and behavior to a class in Java programming language, they are used for two different purposes. Implements keyword is used for a class to implement a certain interface, while Extends keyword is used for a subclass to extend from a super class. When a class implements an interface, that class needs to implement all the methods defined in the interface, but when a subclass extends a super class, it may or may not override the methods included in the parent class. Finally, another key difference between Implements and Extends is that, a class can implement multiple interfaces but it can only extend from one super class in Java. In general, usage of Implements (interfaces) is considered more favorable compared to the usage of Extends (inheritance), for several reasons like higher flexibility and the ability to minimize coupling. Therefore in practice, programming to an interface is preferred over extending from base classes.

Related posts:

Difference Between JSP and Servlets Difference Between JDK and JRE Difference Between Objects and Classes Difference Between Java and C language Difference Between Virtual and Abstract

Filed Under: Programming Tagged With: Extends keyword, Extends vs Implements, Implements keyword, Implements vs extends in Java, Implements vs Extends in Java programming language, Inheritance, inheritance in Java programming, interface in Java, interfaces, Java, multiple inheritance, what is inheritance in Java, what is interface in Java

About the Author: Indika

Indika, BSc.Eng, MSECE Computer Engineering, PhD. Computer Science, is an Assistant Professor and has research interests in the areas of Bioinformatics, Computational Biology, and Biomedical Natural Language Processing.

Comments

  1. AMC says

    November 2, 2019 at 8:47 am

    What a great explenation! Thank you so much for sharing such knowledge.

    Reply

Leave a Reply Cancel reply

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

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Sewing and Embroidery

Difference Between Free and Attached Ribosomes

Difference Between Free and Attached Ribosomes

Difference Between iPhone and Blackberry

Difference Between However and Although

Difference Between Molecular Motion and Diffusion

Difference Between Molecular Motion and Diffusion

Latest Posts

  • What is the Difference Between Foundation and BB Cream
  • What is the Difference Between Cybrids and Hybrids
  • What is the Difference Between Hapten and Adjuvant
  • What is the Difference Between Omphalocele and Gastroschisis
  • What is the Difference Between Autonomic and Somatic Reflexes
  • What is the Difference Between Plagiocephaly and Craniosynostosis
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018 Difference Between. All rights reserved. Terms of Use and Privacy Policy: Legal.