• 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

How to relate two interface ???

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can make relationship between two interface
interface I1 {}
interface I2 {}
without using extending the one with other.
Thanks in adavnce.
Sachin
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think extending is the only way
Is any one aware of other ways to do this???
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sachin
What kind of relationship you are looking for your interfaces? Either it can be "contains" or "extends" that are possible relations here I guess...
Also, whenever we have a relationship we have to have some explicit representation so without doing anything we can just logically know how they are related but can't expect computer to do that for us, right?
Regards
Maulin
 
Sachin Junghare
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question I am trying to ask without extends interfaces means how we contains Interface one members into interface two ....
I just know one way by extending ...but the question is asked me in the interview ....
so i put it here.
Sachin.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can make relationship between two interface
interface I1 {}
interface I2 {}
without using extending the one with other.

If you define interface I3, and both I1 and I2 extend I3, then both I1 and I2 will be of type I3 and therefore related.
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it Possible to do this way..
inteface I1{}
inteface I2{}
class C implements I1,I2{
C(){
}
public static void main(String s[]){
I1=new C();
I2=new C();
}
}
 
Sachin Junghare
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it may be the possible way we can have relationship between interfaces
[code]
interface I1 {}
interface I2 {
class myclass implements I1{}
}
public class A {
public static void main(String arg[]) {
}
}
[code]
right!
Sachin.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sachin
I tried the following,

Here as you notice it doesn't enforce us to implement testI2 in testInterface1 even if "interface testI1 contains testI2". Also, we could extend testI2 seperately via testInterface2 class. So, here it seems that "contains" for interface would only be there for logical grouping because we can't just extend testI2 directly. We have to write testI1.testI2 you know...So essentially "contains" is used for "name space"....
Also, in the example that you give the same argument probably applies as the class inside the interface doesn't really make great sense to me...
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I looked more into my arguments about "contains" relationship b/w interfaces and I found this group discussion
Please refer to the "Oreilly's Nutshell" quote there which says,
"
Nested interfaces are implicitly static ([snip]) and so are always
top level. A nested top-level class or interface behaves just like
a "normal" class or interface that is a member of a package. [snip]
Nested top-level classes and interfaces are typically used as a
convenient way to group related classes.
"
Regards
Maulin
 
Sachin Junghare
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Guys !
Sachin.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic