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 sample ques.

 
Michael Burke
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • 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;
}
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the answer, it seems clear now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic