Showing posts with label Interface extends another interface in Java. Show all posts
Showing posts with label Interface extends another interface in Java. Show all posts

Interface extends another interface in Java

Why interface extends another interface?

Interface won't implement the methods of another interface but just extends them and add additional functionality to class which implements the interface. For example if we have an interface called


public interface telePhone {
 
 public void answerCall();
 public void dail();
 public void sendSMS();
 public void readSMS();
}

Lets assume interface called "telephone" with basic featured phone functionalities like calls and SMS. But when it comes to smart phone we need support for video call, Wifi, Bluetooth etc., along with featured phone functionalities. 


public interface smartPhone extends telePhone {
 
 public void videoCall();
 public void wifiConfig();
}

Here the class which ever implements smartPhone need to implement all the methods of both telePhone and smartPhone interfaces. Since these methods are just functionalities the real implementations based on phones like how they need to implement will be resided. For example if a class called Samsung implements smartPhone the implementation of these all methods will be based on their own logic and if same interface smartPhone is implemented by Nokia then their logic will be different but by functionalities will be remain same across all classes. 

Below are the screenshot reference from Eclipse which says list of methods need to implement when we implements telePhone and list of methods to implement while smartPhone interfaces

Interace extends interface in java













Interace extends interface in java