Interfaces Java - Interfaces Part2 - Can two interfaces with same prototype method can be implemented both at a time - UCS - Unleash-Coding-Skills

Thursday, 24 May 2018

Interfaces Java - Interfaces Part2 - Can two interfaces with same prototype method can be implemented both at a time - UCS


Java Interfaces Part 2:

In this part we can go through a interested question. Can two interfaces with same prototype can be implemented in a single class.

Did it provide output or It throws an error...

Think... Think....

yes it product the output it is enough to implement the method only once.So you can see an example so you can understand it better.

interface A
{
    void x();
}
interface B
{
void x();
}

class R implements A,B
{
public void x()
{
System.out.println("hello");
}
}

public class InterfacePractice1 {
    public static void main(String args[])
    {
     A a  = new R();   
     a.x();
    }
}


Output:

hello

So in this example we can observe two interfaces with same prototype is implemented in a single class R and we got the output.It is one of the interview question in a top company.

To know about basic interface terminology you can visit the link :

Happy coding...............

Tags:
Interfaces in java,Java interfaces, interface,OOPS java, Java interview question, two interfaces implementation in one class java, Interface example java,interface concept java.

No comments:

Post a comment