Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – Extending Interfaces

Same like inheritance where one class can extend/inherit another class, an interface can extend another interface.

Example

interface CustomerDemand1 
{
    public void provideComputers(int num);
    public void provideService(int yr);
}

interface CustomerDemand2 extends CustomerDemand1
{
    public void makeSoftware();
}

class SoftwareCompany implements CustomerDemand2
{
    public void provideComputers(int num)
    {
        System.out.println(num+" computers");
    }

    public void provideService(int yr) 
    {
        System.out.println(yr+" years");
    }

    public void makeSoftware()
    {
        System.out.println("Developed in Java");	
    }
}

class InterfaceExtendedDemo 
 {
    public static void main(String args[]) 
    {
        SoftwareCompany s = new SoftwareCompany();
        s.provideComputers(200);
        s.provideService(10);
        s.makeSoftware();
    }
}

Output

200 computers
10 years
Developed in Java

 

Leave a reply