This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sun qstns - "has a" relationship

 
Santosh Jaiswal
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh
Check out the posts at [url]http://www.javaranch.com/ubb/Forum24/HTML/005222.html[/url

 
Harpal Singh
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic