• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interface in java

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



}
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
syruss kumar
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 148
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic