• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Qn from Sun's samples

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is (d) & (e)
 
Praveen Zala
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic