This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Regarding Interface Concept

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I have small doubt regarding Interface.

Check below code.




here how to find class inter is using which interface method ?

Thank you.
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vicky ma wrote:here how to find class inter is using which interface method ?


Here the class "inter" implements both interfaces (though it happens to have only one method which both interfaces declare).
 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because single class is implementing both the interfaces so "method()" will be common for both the interfaces and method will belong to the class itself so it does not matter with which object are you calling the method.
 
vicky ma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but method belong to which interface ?

there should be some way..
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code will give a compilation error.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krishna,

Can you explain how the compilation will fail for this code?
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vicky ma wrote:but method belong to which interface ?

there should be some way..



why? by declaring the method it properly implements both interfaces
 
vicky ma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why ?

1 should know which interface method he/she has implemented...doesnt 1 required to know it ?
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why ?
1 should know which interface method he/she has implemented...doesnt 1 required to know it ?


The question doesn't make much sense to me. As everyone said, the method that you declared in class inter overrides the method of both interface a and b. Now what else do you want to know. If it were overriding the method of either one of the interface, then you'll get a compilation error as your class inter is not abstract. Basically if the code was like this

So basically in your code method overrides the method of both a and b because if a class doesn't override all the methods of its super-interfaces, then it must be declared abstract...
 
vicky ma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AGGREEED......you may now close the thread...
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic