• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sun sample ques.

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was wondering why 4 and 5 are the correct answers?
Which two demonstrate a "has a" relationship? (Choose two.)
1. public interface Person{ }
public class Employee extends Person{ }
2. public interface Shape{ }
public interface Rectangle extends Shape{ }

3. public interface Colorable{ }
public class Shape implements Colorable{ }

4. public class Species{ }
public class Animal{private Species species;}

5. interface Component{ }
class Container implements Component{
private Component[] children;
}
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When determining if something is a "has a" relationship or an "is a" relationship look to see if it implements or extends a class or if it has a class or instance variable in the class. If it extends the class then you are saying that class A is a Class B. If you have an instance variable, then you are saying Class A has a Class B.
So for the example above, answer 4 and 5 both have instance variables of another class, so you can say Animal has a Species called species and Container has a Component called children.
 
Michael Burke
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answer, it seems clear now.
reply
    Bookmark Topic Watch Topic
  • New Topic