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

Example

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

 

Example

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();
}
}

Output

JavaRace

Multiple inheritance in Java by interface:

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:

Example

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();
}
}

Output

JavaRace
Silan Software

Note:

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.

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment