This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Relationship" Watch "Relationship" New topic
Author

Relationship

Anu
Ranch Hand

Joined: Oct 31, 2000
Posts: 54
I know thatInheritence has "is - a" relationship and aggregation has "has - a" relationship.Can some tell me wht kinda relationship does interface have.
Thanx in advance.
Anukampa
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

Interface is is-a relationship. It is one way we can get multiple inheritance. the other is inner classes.


SCJP
Visit my download page
Anu
Ranch Hand

Joined: Oct 31, 2000
Posts: 54
Randall:
Could u pls tell me how do we get multiple inheritence thru inner classes since i m new to inner classes.
Thanx In advance.
Anukampa
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

from "Thinking in Java":
A question that cuts to the heart of inner classes is this: if I just need a reference to an interface, why don�t I just make the outer class implement that interface? The answer is �If that�s all you need, then that�s how you should do it.� So what is it that distinguishes an inner class implementing an interface from an outer class implementing the same interface? The answer is that you can�t always have the convenience of interfaces�sometimes you�re working with implementations. So the most compelling reason for inner classes is:

Each inner class can independently inherit from an implementation. Thus, the inner class is not limited by whether the outer class is already inheriting from an implementation.

Without the ability that inner classes provide to inherit�in effect�from more than one concrete or abstract class, some design and programming problems would be intractable. So one way to look at the inner class is as the completion of the solution of the multiple-inheritance problem. Interfaces solve part of the problem, but inner classes effectively allow �multiple implementation inheritance.� That is, inner classes effectively allow you to inherit from more than one non-interface.

Anu
Ranch Hand

Joined: Oct 31, 2000
Posts: 54
Thanx Randall. I have got yr point.
Anukampa.
Nasir Khan
Ranch Hand

Joined: Nov 04, 2000
Posts: 135
Isn't implementing an interface 'has a' relationship'
beacuse doing so we 'have' the methods defined by interface.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

you can upcast from a class to the interface it implements so it is definately an is-a relationship.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Relationship
 
Similar Threads
Trying to access the instance variable of Class Bar from Class Foo --------- why error ?
WA #1.....word association
Webservices and .NET
Containment
Composition Vs Inheritance