• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confusion regarding HAS-A realationship  RSS feed

 
Atul Shukla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A {
B b;
}
class B{
C c;
}
Class C{
A a;
}

Now , whisch statements are true?and which are false and why?
1) A HAS-A B
2) A HAS-A C (because B HAS-A C)
3) A HAS-A A (because A HAS-A B and B HAS-A C and C HAS-A A)

-Atul
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might at least make some attempt to disguise your homework...
 
Atul Shukla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! Peter i am not disguising my homework , believe me, and so why should i attempt to.....
[ November 12, 2006: Message edited by: Atul Shukla ]
 
Atul Shukla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do anyone please clear my confusion,
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual way to do questions like this is for you to tell us what you think the answer is and why, and then someone will correct you (if you are wrong).
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Atul Shukla:
Hey! Peter i am not disguising my homework , believe me, and so why should i attempt to.....


Posting a multiple-choice question sure looks like trying to get someone to do your homework. If it really isn't homework, then you have my apologies. If it is homework, then my suggestion that you try to disguise it was sarcastic - really I'd prefer people not to waste my time with their homework, when they should be making the effort to learn for themselves.

I, and I guess many others, do not mind helping with homework, providing the poster makes it clear that they have tried (and I don't just mean saying "I tried") and asks for help on a particular aspect of the question, not just an answer to the whole question. Another poster has already suggested you do this, for your "has-a" question.

Regarding "has-a", I think it is a bit difficult to answer the question, because "has-a" is a bit ambiguous in Java. Your classes A, B and C each have a field that is a reference to an object of one of those classes, but the Java language syntax does not make it clear who owns (and hence "has-a") the actual objects pointed-to.

Compare to C++, where an object can have a field that is another object, not just a reference to another object. So, if class A has a field that is of type class B, one can pretty safely say "A has a B". Your classes A, B and C couldn't be in C++, though, because you'd end up with "A has an A", and an infinite-sized object.
 
Atul Shukla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,
first i apolgize for putting up question in such a format,
actually i haven't think that muchh before puuting the question,

i am preparing for SCJP, and while taking a mock exam, goine through a question of IS-A and Has-A relationship , this question just striked in my mind that time and i really not able to find the correct answer,
so i posted it here , and i asked the question in such a manner, Really sorry ,and i haven't intended to put sarcastic questions..but it happened :roll:

-Atul
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's make those abstract things concrete, shall we?

I have a dog. My dog has a tail. So do I have a tail or not?
 
Atul Shukla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it!!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:

I have a dog. My dog has a tail. So do I have a tail or not?


If you "have a" dog, is that consequently a "has-a" relationship?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a foot and my foot has a toe. Does that have the same answer as the dog & tail?

The word "ambiguous" was used above. Amen. We'd have to know how the author of the question defines "has a" and the best way to learn that might be to give up and look up the answer for the question.

Intuitively I'd say NO to the original #2 and #3. A has B, but A doesn't (yet) depend on "B has C" so B might remove its C and A wouldn't know the difference.
[ October 26, 2006: Message edited by: Stan James ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
The word "ambiguous" was used above. Amen. We'd have to know how the author of the question defines "has a" and the best way to learn that might be to give up and look up the answer for the question.


Exactly. That's what I dislike about the notion of a "has-a relationship" - everybody thinks he understands what it means, but everyone uses a different definition (or typically on at all, but some form of intuitive understanding).

That's OK for analyzing a problem, but when it comes to design, I think we should use more precise terms, such as association, aggregation and composition.
 
Atul Shukla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i encounter the question on SCJP exam , what option should i go for.

Thank you.
-Atul
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers!


Atul Shukla posted October 27, 2006 12:50 AM
If i encounter the question on SCJP exam , what option should i go for.



In this case you should institute proceedings against Sun Microsystems (Santa Clara, Calif.) ;-)

No, I'm sure (or: almost certain...) the exam designers set up clear questions, whithout any doubts about the correct answer.

You simply won't see such an ambiguous question on the exam.


Yours,
Bu.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!