This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic