• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

About is-a and has-a?

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any one explain about is-a and has-a? what is the difference between those?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

When we talk about IS-A , we actually mean that an Object is of type another object. i.e for example , a Laptop is a Computer. Both are computers, but Laptop is more specialized for say mobility. In the same way, Tiger is a Feline. Here Tiger is more specialized one, or rather very much pin pointed when compared to its species Feline. IS-A is a relation between More generic to Most specific and which has a Father and Child relation. Also not just classes extending each other, but this concept holds good even for inheritance and its implementation. A ball has qualities of a rubber. That is ball is a rubber. Ball may have more specific functionalities like bouncing which a plain rubber may not have. But a ball to be called as ball, should have the qualities of a rubber ( Unless ball is made up of something else). This is about IS-A.

Coming to HAS-A, it is about possessing. A computer has a Processor. A computer is composed of different components like processor, RAM, HDD etc. So Computer has processor. There is HAS-A relation.

Putting in general terms, We ARE Humans. This is a IS-A relation. We have limbs. This is a HAS-A relation. Hope this should clarify your doubt.
 
swati cha
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks chandra for your detailed explanation..
Can you give any exaple code using is-a and has-a?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IS-A:

Here you can say: Mercedes IS-A Car

HAS-A:

Here you can say: Mercedes HAS-A (very special Bridgestone) Tire
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!


IS-A:
class Animal {}
class Dog extend Animal{}
then we can say "Dog IS-A Animal"
other example:
interface runable{}
class fast implements runable()
then we can say "fast IS-A runable"
in other words,if "A instanceof B =true",so we can say "A IS-A B"


HAS-A:
class Horse{
Halter myHalter;
}
then we can say,Horse HAS-A Halter.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"swati", please check your private messages. You can see them by clicking My Profile.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic