Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Sun qstns - "has a" relationship

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

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic