Interfaces are used as super classes whose properties are inherited by a class. Thats why it is necessary to create a class that inherits the given interface. This is achieved as follows
class ClassName implements InterfaceName { Body of class } //The more general form of implementation is class ClassName extends superclass implements Interface1, Interface2........ { body of className }
Here it represents that a class can extend another class while implementing interfaces
Let us see a program to understand this concept
interface Print { void display(); } class Printing implements Print { public void display() { System.out.println("JavaRace"); } } class InterfaceDemo { public static void main(String args[]) { Printing ob = new Printing(); ob.display(); } }
JavaRace
If a class implements multiple interfaces, or an interface extends multiple interfaces i.e. known as multiple inheritance.
Img Insert Here.
Let's see the following program:
interface Test1 { void display(); } interface Test2 { void show(); } class Simple implements Test1, Test2 { public void display(); { System.out.println("JavaRace"); } public void show() { System.out.println("Silan Software"); } } class MultipleDemo { public static void main(String args[]) { Simple s = new Simple(); s.display(); s.show(); } }
JavaRace
Silan Software
Multiple inheritance is not supported in case of class. But it is supported in case of interface because there is no ambiguity as implementation is provided by the implementation class.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc