my dog learned polymorphism*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Interface in java" Watch "Interface in java" New topic
Author

Interface in java

syruss kumar
Ranch Hand

Joined: Jul 23, 2009
Posts: 93
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{
@override
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.


S.D. MADHAN
Not many get the right opportunity !
syruss kumar
Ranch Hand

Joined: Jul 23, 2009
Posts: 93
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

Hi,

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>

Thanks


The important thing is not to stop questioning.Curiosity has its own reason for existing.
 
Don't get me started about those stupid light bulbs.
 
subject: Interface in java