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
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.
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
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
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.