wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is-A relationship Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is-A relationship Doubt" Watch "Is-A relationship Doubt" New topic
Author

Is-A relationship Doubt

sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
Hi
from the recent post yesterday i saw that intarface implementation ia HAS-A relationship
I always think that it is IS-A relationship can you please solve my doubt
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Puluk,

You should post the issue, so that ranch hand could give the solution. But so far your first statement goes "interface implemetation is HAS_A relationship". That looks wrong.



Conclusion: 1- A implements E
2- A IS-A(n) E
3- E's reference can refer to the instance of class A or its subclasses (provided A implements interface E); without causing any ClassCastException at runtime.

And finally there is nothing HAS-A as I see this.

Yeah a class definition can itself keep the interface reference, so there can be HAS-A relationship and I think you are talking about this issue.

Thanks and Regards,
cmbhatt


cmbhatt
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
The relationship is HAS - A when a class implements an interface.
When a class extends another class, the relationship is IS - A


this is what i saw in the previous posts.thats the reason i raised a doubt with you to confirm
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Pulak,


So what you concluded, let me know that too.


Thanks and Regards,
cmbhatt
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
I just want to conclude from your explanataion please
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Puluk,


1- The relationship is HAS - A when a class implements an interface.
2- When a class extends another class, the relationship is IS - A


The first one is wrong and second is true.

Either you extend a class or implement an interface, there will always be IS-A relationship. You think yourself about this issue. Why would it go HAS-A relationship.

Dog extends Animal, so Dog is a Animal.
If Person class implements java.io.Serializable interface, so the class Person is Serializable and NOT has a Serializable.

If your class implements Comparable interface then the instances of your class are comparable and NOT has-A Comparable.

Is my message conveyed to you well ?

Thanks and Regards,
cmbhatt
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
Ya Iam satisfied .thanks so much
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
Hi ,

In oo, the IS-A relationship is based on inheritance. for eg BMW IS-A Car. so you can express IS-A relationship in java using extends keyword.


HAS-A relationship is based on usage rather than inheritance. In other words, class A HAS-A B if code in class A has a reference to an instance of class B. For eg

BMW IS-A Car.
BMW HAS-A TubeLessTyre


bye for now
sat
 
Don't get me started about those stupid light bulbs.
 
subject: Is-A relationship Doubt