aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Has-A Relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Has-A Relationships" Watch "Has-A Relationships" New topic
Author

Has-A Relationships

Saurabh Verma
Ranch Hand

Joined: Aug 13, 2007
Posts: 38
Hi,

I having problem in Has-A relationships concept.
What is the practical use of this?How can we use in normal code?

Thnaks.
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Hi,

Suppose that you have two classes, Car and Steering.

As we all know, all cars have a steering, so the following code illustrates the concept of the HAS-A relationship:



From the code above, and specifically in the Car class, you can see that the Car class has a reference to a Steering, so it is said that Car HAS-A Steering.

Did you get it ?


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Saurabh Verma
Ranch Hand

Joined: Aug 13, 2007
Posts: 38
Thanks Vassili!!

But I still have some confusion.Now class Car has a reference variable of class Steering.What is the use of that reference variable?
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
The use of it is as the use of any other object you use in any application ...
Saurabh Verma
Ranch Hand

Joined: Aug 13, 2007
Posts: 38
Thank you!!
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Anytime ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Has-A Relationships