Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sun sample question

 
Satheesh Kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai
I found this question in "sun site " for "has a " relationship..,
now can anyody help me out in this question

Which two demonstrate a "is a" relationship?
a. public interface Person{ }
public class Employee extends Person{ }
b. public interface Shape{ }
public interface Rectangle extends Shape{ }
c. public interface Colorable{ }
public class Shape implements Colorable{ }
d. public class Species{ }
public class Animal{private Species species;}
e. interface Component{ }
class Container implements Component{
private Component[] children;
}
 
Rajiv Ranjan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will go for a, b and c.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference between "is a" and "has a" is whether or not you extend another class, or just have member variable of the class.
So if Employee extends Person, then you are saying the Employee is a Person becuase they have all the behaviors of the Person, or they inherit all of the methods of class Person.
But if you have a class Employee and in that class is a memeber variable Person, you are saying Employee has a Person because inside of thier class they have another class Person.
Implements is sometimes called "is like a" but it is also really an "is a" becuase you have to implement all of the methods to make it a class otherwise it has to be an abstract class or another interface.
With all that said, take a look at it again, and see if you can figure out the answer.
Bill
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing, the Sun question asks which TWO represent a HAS A relationship, not is a. Don't want to confuse people because there are 3 is a and 2 has a.
Bill
 
Satheesh Kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill and Rajiv
I did not mean to confuse people, but my question was to get an answer for "is a" relation
If I had done so.., I am extremely sorry..,
Thanks for the explanation, now I am clear with the ans

Originally posted by Satheesh Kumar:
Hai
I found this question in "sun site " for "has a " relationship..,
now can anyody help me out in this question

Which two demonstrate a "is a" relationship?
a. public interface Person{ }
public class Employee extends Person{ }
b. public interface Shape{ }
public interface Rectangle extends Shape{ }
c. public interface Colorable{ }
public class Shape implements Colorable{ }
d. public class Species{ }
public class Animal{private Species species;}
e. interface Component{ }
class Container implements Component{
private Component[] children;
}

 
Kirti Dhingra
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
answer is D & E b'coz they contain a member variable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic