Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

IS-A and HAS-A relationship

 
Ranch Hand
Posts: 39
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood is-a relationship is inheritance but I am not understanding has-a relationship.

Has-A means an instance of one class “has a” reference to an instance of another class or another instance of same class.



can anyone explain here what is has-a relationship( preferably with simple real time/code example )
 
Rancher
Posts: 4603
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


A Car has-a(n) Engine.

Hopefully that's not too basic.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now it's up to you to provide the code snippet for:
a) a car has 4 wheels
b) a house has a list of rooms
 
On top of spaghetti all covered in cheese, there was this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic