Google+

129. Interface inheriting another Interface






Like class inheriting another class, we can have an interface inheriting another interface using the same 'extends' keyword as shown in the below example:

public Interface Interface1 extends Interface2
{
      //Body of the Interface1
}

Lets implement this on Eclipse IDE:

1.Create an interface 'Interface1' which defines three methods as shown below:



2. Create an interface 'Interface2' which inherits 'Interface1' and also defines only one method as shown below:



3. Create a class 'ClassOne' which implements 'Interface2' as shown below:



4. Create a class 'InterfaceInheritedDemo' to create an object for 'ClassOne' class to access all its implemented methods of Interface1 and Interface2 as shown below:



5. Save and Run the 'InterfaceInheritedDemo' class
6. Observe that the output is displayed in the console as shown  below:



Download this project:

Click here to download the project containing the class files used in this post (You can download this project and import into Eclipse IDE  on your machine)




Please comment below to feedback or ask questions.

'Exception Handling' will be explained in the next post.


No comments: