This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Interface Concept

 
vicky ma
Ranch Hand
Posts: 38
  • 0
  • 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.
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • 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).
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but method belong to which interface ?

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

Can you explain how the compilation will fail for this code?
 
Jack Bento
Ranch Hand
Posts: 34
  • 0
  • 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
  • 0
  • 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 ?
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AGGREEED......you may now close the thread...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic