aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding Interface Concept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding Interface Concept" Watch "Regarding Interface Concept" New topic
Author

Regarding Interface Concept

vicky ma
Ranch Hand

Joined: May 13, 2009
Posts: 38
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

Joined: Mar 24, 2008
Posts: 3858

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

Joined: Jan 14, 2010
Posts: 317

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

Joined: May 13, 2009
Posts: 38
but method belong to which interface ?

there should be some way..
KrishnaPrasad raghavan
Ranch Hand

Joined: Oct 28, 2008
Posts: 46
This code will give a compilation error.
Ravinderjit Singh
Ranch Hand

Joined: Jan 13, 2010
Posts: 78
Krishna,

Can you explain how the compilation will fail for this code?
Jack Bento
Ranch Hand

Joined: Jun 14, 2009
Posts: 34
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

Joined: May 13, 2009
Posts: 38
why ?

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

Joined: Aug 03, 2008
Posts: 9317
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
vicky ma
Ranch Hand

Joined: May 13, 2009
Posts: 38
AGGREEED......you may now close the thread...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Interface Concept