• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Is-A relationship Doubt

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pulak,


So what you concluded, let me know that too.


Thanks and Regards,
cmbhatt
 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to conclude from your explanataion please
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya Iam satisfied .thanks so much
 
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I child proofed my house but they still get in. Distract them with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic