aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sun qstns - Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sun qstns - "has a" relationship" Watch "Sun qstns - "has a" relationship" New topic
Author

Sun qstns - "has a" relationship

Santosh Jaiswal
Greenhorn

Joined: Oct 04, 2000
Posts: 26
6. Which two demonstrate a "has a" relationship? (Choose two.)
public interface Person{ }
public class Employee extends Person{ }
public interface Shape{ }
public interface Rectangle extends Shape{ }
public interface Colorable{ }
public class Shape implements Colorable{ }
public class Species{ }
public class Animal{private Species species;}
interface Component{ }
class Container implements Component{
private Component[] children;
}
Can any one explain that what is difference between "has a" and "is a" relationship
Thanks
shanks iyer
Ranch Hand

Joined: Oct 16, 2000
Posts: 47
Santosh,
Inheritance defines a is a relationship I mean a relationship between superclass and a a subclass i mean the object of subclass can be used anywhere where the superclass can be used
let us take the xample you have cited above
public interface Person{ }
public class Employee extends Person{ }
in this example an employee is a person so an employee can be used in case of person so this demonstrates the is a relationship
simliar is the case for subsequent examples
2.public interface Shape{ }
public interface Rectangle extends Shape{ }
3.public interface Colorable{ }
public class Shape implements Colorable{ }
In the above two case also the same thing applies as in the second one rectngle is a shape and shape is colorable.
But has a relationship is aggregration kind of a relationship that is shared betwwen a class and its instance constituents like
in your question the eg 4 and eg 5
4.public class Species{ }
public class Animal{private Species species;}
5.interface Component{ }
class Container implements Component{
private Component[] children;
}
In the 4th eg class animal has an instance of species and in the 5ht eg class container has a component so 4ht and 5th are are the only right options If iI am wrong please feel free to correct me.
Regards,
Shankar.
greg clarke
Greenhorn

Joined: Oct 06, 2000
Posts: 25
Santosh
Check out the posts at [url]http://www.javaranch.com/ubb/Forum24/HTML/005222.html[/url

Harpal Singh
Ranch Hand

Joined: Oct 10, 2000
Posts: 229
santosh,
understanding has a and is a relationship is very simple ...only remember one mantra............
"Car is a Vehicle,Car has four wheels"
now is a relation:Car extends Vehicle.......
has a relationship:int wheel1;int wheel2;
so where ever you see extends keyword that means is a relationship..........and where ever you see the veriables defined that means has a relationship........
Hope it is clear to you,
Harpal
Travis Gibson
Ranch Hand

Joined: Oct 17, 2000
Posts: 100
Thanks Harpal,
That is by far the most clear explanation I have ever read on is a/ has a relationships. Thanks again.
Originally posted by Harpal Singh:
santosh,
understanding has a and is a relationship is very simple ...only remember one mantra............
"Car is a Vehicle,Car has four wheels"
now is a relation:Car extends Vehicle.......
has a relationship:int wheel1;int wheel2;
so where ever you see extends keyword that means is a relationship..........and where ever you see the veriables defined that means has a relationship........
Hope it is clear to you,
Harpal


Regards,<BR>Travis M. Gibson, SCJP<BR>Java Developer<BR>www.travismgibson.com<BR>travis@travismgibson.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sun qstns - "has a" relationship