Interface extends with interface

In this blog, we will see one interface extends with another interface. Using of this structure, class needs to implements with only sub interface.

Interface extends another interface

 

Interface1                              

|           [ extends ] [ Implements ]

Interface2

|           [ Implements ] [ extends ]

Class

 

 

 

Inter1 in InterPack1 package

package InterPack1;

public interface Inter1   // Interfaces

{

                public int x = 10;                // it’s final variable          

                public void method1();  // Indexing | Only Dec

}


Inter3 in InterPack2 package

package InterPack2;

import InterPack1.*;

public interface Inter3 extends Inter1

{

                public void method3();  // dec only | indexing

}


Class c in classStore Package

package classStore;

import InterPack2.*;

public class C implements Inter3

{

                public void method1()

                {

                                System.out.println(“Inter 1”);

                }

                public void method3()

                {

                                System.out.println(“Inter 3”);

                }

}


Example3 class in mainPackage package

package mainPackage;

import InterPack2.*;

import classStore.*;

public class Example3

 {

                public static void main(String[] args)

                {

                                // Just create Inter3 object

                                Inter3 obj = new C();

                                obj.method1(); // call to 1st Interface method

                                obj.method3(); // call to 3rd Interface method

                }

}


Output:

Inter1

Inter3

 

Video available on YouTube.

 


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

846total visits,8visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

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

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint