Google+

119. Class implementing multiple Interfaces






A class can implement more than one interfaces by separating the interfaces with commas ' , '  as shown below:

class ClassName  implements Interface1, Interface2Interface3
{

     //Body of the class

}

Lets implement this on Eclipse IDE:

1. Create Interface 'Interface1'  as shown below:



2. Create Interface 'Interface2' as shown below:

















3. Create Interface 'Interface3' as shown below:



4. Create Interface 'Interface4' as shown below:



5. Create a class which implements all the above interfaces as shown below:



6. Create a class 'MultipleInterfaceDemo' which creates an object for 'ClassOne' class to access all the methods in it as shown below:



7. Save and Run the 'MultipleInterfaceDemo' class
8. Observe that the output is displayed in the console as shown below:



Download this project:

Click here to download the project containing the 'Interface1', 'Interface2', 'Interface3', 'Interface4', 'ClassOne' and 'MultipleInterfacesDemo' files used in this post (You can download the project and import into Eclipse IDE on your machine)




Please comment below to feedback or ask questions.


'Single Interface Implemented by Multiple Classes' will be explained in the next post.



No comments: