Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from sun

 
anushree ari
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A {}
class B {
private A myA = new A();
}
Which two statements are true about the relationship between class A and class B? (Choose two.)

A maintains no relationship with B

B maintains no relationship with A

B maintains a "one to many" relationship with A

The relationship can be described with a has-a clause

The relationship can be described with an is-a clause

i choose "is" a relationship, but ans is "has " a relationship.
anybody correct me
thx
 
david eberhardt
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

class B can have member variables, methods, and also contain other objects as members.
What we have here is an example of class A being used as a member of class B because there is some (undefined) functionality we want to use in our class B.
An similar example might be:
class Wheel {
}
class Car {
Wheel rightFront = new Wheel();
Wheel leftFront = new Wheel();
}
a Car has-a wheel ( actually has 4 of them right?)
---------------------------------
an IS-a relationship is about inheritence:
class Animal {
boolean canFly = false;

}
class Bird extends Animal {
boolean canFly = true;
fly() {
// implementation top secret
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic