This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Qn from Sun's samples Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Qn from Sun Watch "Qn from Sun New topic
Author

Qn from Sun's samples

Praveen Zala
Ranch Hand

Joined: Jul 02, 2000
Posts: 118
Pls anyone answer this with Xplanations:
Which two demonstrate a "has a" relationship? (Choose two.)
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;
}

TIA
Praveen Zala
asim wagan
Ranch Hand

Joined: Nov 14, 2000
Posts: 62
The answer is (d) & (e)
Praveen Zala
Ranch Hand

Joined: Jul 02, 2000
Posts: 118
I know that it is d and e.....I want some detailed
explanations....regarding the same....
(P.S - I know that Sun's sitehas teh answers, but I need
to know the explanation)
Kathy Rogers
Ranch Hand

Joined: Aug 04, 2000
Posts: 103
A 'has a' relationship indicates that a class 'has a' a certain property - that is a member variable. An 'is a' relationship indicates that a subclass 'is a' type of the superclass. The statement 'A car is a vehicle' implies
Class Car extends Vehicle
But the statement a car has a steering wheel implies:-
class Car{
SteeringWheel theWheel;
}
where SteeringWheel is a class member variable.
So if we look at your example:-
a,b,c all involve empty classes and interfaces - no class member variables.
But in d, the Animal class has a class member variable, species.
And in e, the class Container (which incidentally 'is a' Componenet) has a class member variable, children.
Hope this makes things a bit clearer.
Kathy
Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
Refer : http://www.javaranch.com/ubb/Forum24/HTML/006021.html

a)public interface Person{ }
public class Employee extends Person{ }
This is wrong ! A class cannot extends an interface
b)public interface Shape{ }
public interface Rectangle extends Shape{ }
This is is-a relationship [b]
c)public interface Colorable{ }
public class Shape implements Colorable{ }
[b] This is a realize relationship

d)public class Species{ }
public class Animal{private Species species;}
This is a has-a relationship.
e)interface Component{ }
class Container implements Component{
private Component[] children;
}
This is a has-a relationship
So the correct answers are d and e.

HTH
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Qn from Sun's samples
 
Similar Threads
Sun sample ques.
Help plz
has a relationship
sun sample question
Sun qstns - "has a" relationship