Java Interface Inheritance – Example – Explanation – Screenshot – Simple terms for a Beginner
Interfaces were introduced by the Java Designers to support multiple inheritance. Not only that, interfaces give a template methods from which new classes can be developed easily. Interface gives plan of methods required to achieve a task like a blue print for a house.
Interface should contain all abstract methods and not even one concrete method. This is where interface differs from abstract class. One more visible difference is using implements with interfaces and extends with abstract classes and concrete classes.
Following is the Example on Java Interface Inheritance
public abstract void storeData(String name, int age);
public abstract void calculateSalary(int basicPay, int houseRent);
public class Officer implements Employee, Accounts
public void storeData(String name, int age)
System.out.println("Employee Name: " + name + " and Age: " + age);
public void calculateSalary(int basicPay, int houseRent)
System.out.println("Employee Total Salary Rs." + (basicPay+houseRent));
public static void main(String args)
Officer o1 = new Officer();
The Java Interface Inheritance involves two interfaces Employee and Accounts and one class Officer implementing the interfaces. Being interfaces, they contain only abstract methods and Officer overriding all the abstract methods.
Following links of this same Web site gives you indepth knowledge of Interfaces
1. Another Example on interfaces: Interfaces – Partial implementation of Multiple Inheritance
2. Inheritance in between interfaces: Play with Implements
3. Inheritance with multiple interfaces and classes: Extends Implements