Implements vs. Extends

Difference Between Implements and Extends

Implements and extends are the word related to Java language. Java language facilitates transfer of extra function to a new class. These two are the key words of Java. The word ‘Implements’ is used to implement an interface. The word extends is use to inherit from a class. Other object oriented programming language such as C# and VB NET have also the concepts of inheritance and interfaces. But they offer different syntax for the application of those concepts. Let us find out what are ‘implements’ and ‘extends’ in Java programming language.

 Extends

‘Extends’ is used for the implementation of the concept of inheritance in Java language. Inheritance gives code rescue as it allows extending properties of an existing class to a new class. A subclass inherits all the attributes and methods of its parent class when the subclass extends the parent class. In Java a subclass cannot extend multiple classes. So, extends cannot be used for multiple inheritance. For this interfaces are used.

Implements

‘Implements’ is used for the implementation of an interface by a class in Java language. In Java interface is abstract. It is used to specify a contract to be implemented by classes implementing that interface. An interface contains method signature and declarations. An interface should implement all methods defined in that interface. Or it should be declared as abstract class. In Java, an interface type is an object reference. This object must be null or have an object of a class. Multiple interfaces to a single class can be implemented with the help of the keyword ‘implements’. A class can be extended by an interface but it cannot implement another interface.

Difference between Implements and Extends

In Java programming language, the keywords Implements and Extends provide mechanism to inherit attributes to a class. Their purposes are different. The Extends is used for a subclass to extend from a super class while Implements key word is used to implement an interface. A class needs to implement all the methods of the parent class while implementing an interface. But it may or may not override the methods when a subclass extends a super class.

Another difference is that a class can implement multiple interfaces but it can merely extend from one super class. Implements or an interface is considered more favorable than Extends or inheritance.

 

Category: VS  |  Tags: