Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

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
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic