File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Interface in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Interface in java" Watch "Interface in java" New topic

Interface in java

syruss kumar
Ranch Hand

Joined: Jul 23, 2009
Posts: 100
HI all,

I have created 2 interfaces with same method signature and implemented that in a class like below

Interface a{

public void test();

Interface b{

public void test();

class PlayJava implements a,b{
public void test(){


1.why its implemented only one method its even throwing any compilation error or runtime error?
2.How JVM handle this.

thanks in advance


All search starts with beginner's luck and all search ends with victor's severly tested.
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

1. This will not result in compilation error as JVM considers each a valid Java entity.

2. Java will execute the method implemented in the PlayJava class.

Not many get the right opportunity !
syruss kumar
Ranch Hand

Joined: Jul 23, 2009
Posts: 100
Thanks devaki,

Yes it will not throw any compilation exception.It will work perfectly but how JVM handles these kind of scenarios that im really confusing .

Please can you clarify me.

Thanks in advance
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146


What compiler sees that if you are implementing the interfaces then you have to override all the methods defined in it.
so your class follows that contract.
There in no ambiguity for the compiler in calling the method.

But if you take the case defined below

at line 1 there is an error from compiler which says "The field value is ambiguous"
so you you want to access a particular constant you have to access it line <interface>.<variable>


The important thing is not to stop questioning.Curiosity has its own reason for existing.
I agree. Here's the link:
subject: Interface in java
It's not a secret anymore!