• Networking
  • Programming
  • DBMS
  • Operating System
  • Internet
  • Hardware
  • Software

Tech Differences

Know the Technical Differences

Difference Between extends and implements keywords in Java

extends and ImplementsThe keywords extends and implements are used to inherit the features of an already existing parent block in newly created child block. Using extends keyword, a newly created class (subclass) can inherit the features of an existing class (superclass). Using implements keyword a newly created class can implement all the methods of an interface.

The primary difference between keywords extends and implements is that a class extends another class to inherit all its members whereas, a class implements an interface to inherit all it methods and implement them according to its requirement. There are some other differences between keywords extends and implements discussed in a comparison chart shown below.

Content: extends Vs implements

  1. Comparison Chart
  2. Definition
  3. Key Differences
  4. Conclusion

Comparison Charts

Basis for ComparisonExtendsImplements
Basic The extends keyword is used to create a subclass using features of a super class.The implements keyword is used for the implementation of an interface
MethodsThe extends keyword may not override all the methods of a super class.The implements keyword has to implement all the methods of an implemented interface.
ClassA class can extend only one super class.A class can implement multiple interafaces.
InterfaceAn interface can extend more than one interface. An interface cannot implement another interface.

Definition of extends keyword

Inheritance being an important concept in Object Oriented Programming, is achieved when a subclass extends an another superclass. A subclass is allowed to extend only one superclass. A class can never extend more than one super class in Java. When a class extends another class, it can override the methods defined in a superclass. Let us understand keyword extends with the help of an example.

class A {
String s;
A(String s1) {
s=s1;
}
// display string
void display() {
System.out.println(+ s);
}
}
class B extends A {
String i;
B(String s1, String i1) {
super(s1);
i = i1;
}
void dispaly() {
super.dispaly(); /*display() of class A invoked.*/
System.out.println(+ i);
}
}
class Override {
public static void main(String args[]) {
B ob = new B(Tech, Differences);
ob.display(); /* display of class B invoked*/
}
}
/* out put */
Tech
Differences

In above code, you can observe that class B has extended class A and has overridden the method display( ) defined in class A. In a similar way an interface can extend more than one interface at a time. As interface do not have to implement any method of the extended interface, hence, it is allowed to inherit multiple interfaces at a time.

Definition of implements keyword

Using the keyword implements, a class inherits all the methods in an interface. When a class implements an interface, that class has to implements all the methods of implemented interface. An interface can never implement another interface, as implements keyword promises implementation of the methods but an interface never implements methods in it, so it is impossible for an interface to implement another interface. Let us understand implements keyword with the help of an example.

interface strings{
void display(String s);
}
interface integer{
void show(int i);
}
class Demo implements strings, integer{
void show(int i){
System.Out.Println("integer value:" +i);
}
void display(String s){
System.Out.Println("string value:" +s);
}
}
class Demo_main{
public static void main(string args[]){
Demo d = new Demo();
d.display("TechDifferences");
d.show(2);
}
}

/* output */
TechDifferences
2

As in the code above you can see that the class demo implements two interfaces strings and integer and has implemented the methods declared in both the interfaces that are display() and show().

Key Differences Between extends and implements

  1. A class can inherit another class, or an interface inherits other interfaces using a keyword extends whereas, a class can implement an interfaces using a keyword implements.
  2. A  subclass that extends a superclass may or may not override all the methods in a superclass. On the other hand, a class implementing an interface has to define/implement all the methods of that interface.
  3. A class can implement any number of an interface at the same time. On the other hand, a class can extend only one super class.
  4. An interface can extend any number of interfaces, but an interface can never implement any other interface as implementing means defining the methods and interface always have abstract methods so an interface can never implement another interface.

Conclusion

I conclude the discussion saying that implementing an interface makes the code more flexible than extending a class. As it avoids the restriction of inheriting only one super class in Java. Using implements keyword a class can inherit features of more than one interfaces.

Related Differences:

  1. Difference Between Super Key and Candidate Key
  2. Difference Between Inheritance and Polymorphism
  3. Difference Between Class and Interface in Java
  4. Difference Between Character Array and String
  5. Difference Between String and StringBuffer Class in Java

Leave a Reply Cancel reply

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

Top 10 Differences

  • Difference Between OLTP and OLAP
  • Difference Between while and do-while Loop
  • Difference Between Guided and Unguided Media
  • Difference Between Preemptive and Non-Preemptive Scheduling in OS
  • Difference Between LAN, MAN and WAN
  • Difference Between if-else and switch
  • Difference Between dispose() and finalize() in C#
  • Difference Between for and while loop
  • Difference Between View and Materialized View
  • Difference Between Server-side Scripting and Client-side Scripting

Recent Addition

  • Difference Between Java and Python
  • Difference Between PHP and HTML
  • Difference Between GPS and GNSS 
  • Difference Between Virtualization and Containerization
  • Difference Between Storage and Memory

Categories

  • Artificial Intelligence
  • DBMS
  • Hardware
  • Internet
  • Networking
  • Operating System
  • Programming
  • Software

Copyright © 2025 · Tech Differences · Contact Us · About Us · Privacy