Skip to main content

Q) How to create has-a relationship in java?




A)
make reference of one class as an instance variable in another class.
Ex:
Class car
{
   Gear g;
}
->car object has “has-a” relationship with Gear object.




  

Comments