This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Master Exam Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Master Exam Error" Watch "Master Exam Error" New topic
Author

Master Exam Error

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Hi all...

There seems to be a discrepancy between a question in the 1st Master Exam and the 3rd Master Exam.
The question is of the type:Select all that apply and is regarding HAS-A relationships.
I know that it is Question 4 on the 3rd Exam,but I forget what the number of the question on the 1st Exam is.

Anyways,the reference for one states that:

-HAS-A relationships are always defined with instance variables

whilst the other reference states that:

-HAS-A relationships may be defined with class variables as well

Please clarify


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Well I think only the first option is correct.

-HAS-A relationships are always defined with instance variables

Read this for more details


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
But Ankit masterexam has this answer:

-HAS-A relationships may be defined with class variables as well

So what to choose in final exam, if we get this question.


Master exam says this is also a has-a relationship.

SCJP 6
Bindu Lakhanpal
Ranch Hand

Joined: Oct 17, 2008
Posts: 165

A class variable simply means,one copy shared by all objects.
So all Car objects will have (same) Engine object.
So, Car has an Engine must be true( even if all Car objects have the same Engine object).
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

daisy lakhanpal wrote:A class variable simply means,one copy shared by all objects.
So all Car objects will have (same) Engine object.
So, Car has an Engine must be true( even if all Car objects have the same Engine object).


But then it will be such that all cars have the same engine. So I don't think has-a relationship can be represented by static fields...
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Yes..that makes since...if only one car can have an engine then we definitely can't define the relationship as
CAR HAS-A ENGINE.That would be incorrect.Thanks everybody
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952


But what about this example? Do not all Honda Car will share a same HONDA logo?
What will you say this relationship?
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
This needs official clarification. I am inclined to believe that static variables of the class involve a Has-A relationship also. But I can see how this can be construed differently. So, until we get an official answer, I will remain in suspense.


All code in my posts, unless a source is explicitly mentioned, is my own.
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Me too
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
So a right example could confuse peoples. Right na!!!

Please any sheriff or author clear this doubt :-(
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Any official word on this?
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
In K&B
class A Has-A B if code in class A has a reference to an instance of class B.

It doesn't mention static variable, but still official word needed....... :?:


SCJP 6
How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Sachin Adat wrote:
In K&B
class A Has-A B if code in class A has a reference to an instance of class B.

It doesn't mention static variable, but still official word needed....... :?:


Means you wanna say:

-HAS-A relationships may be defined with class variables as well
kshitij dogra
Ranch Hand

Joined: Dec 28, 2008
Posts: 39
yup,

has-a relationship can exist for both instance and class variables. I couldn't find any official statements segregating the two though..


SCJP 5.0 - 100%
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
Now this should be official
marc weber wrote:"I would say that static variables do constitute a HAS-A relationship.
Note that HAS-A is typically contrasted with IS-A. That is, composition vs. inheritance. Whether a field is associated with the class or with an instance, it's still composition."
here http://www.coderanch.com/t/269872/Programmer-Certification-SCJP/HASA#1253435


Maybe marc wanted us to search for it..........
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8805
    
    5
While this is a bit murky, I think we're going to agree that statics CAN be used in has-a relationships. It's possible that we'll find a Java authority that changes our mind, but we haven't yet.

The good news is that I'm pretty sure you won't find this distinction on the real exam.

hth,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Maybe the reason why we didn't get any official response is that this concept is a little murky and not well defined. Notice that Marc is just saying that he "would say", he is not stating any official position from the Sun SCJP test creators. Any way to reach these folks? If not, I'm afraid we'll have to pray that this type of question is not in the exam.

EDIT: I guess Bert replied as I was replying. Interesting that he also used the word "murky" And yes, Bert's response sounds reasonable. Thanks for responding, Bert.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Master Exam Error
 
Similar Threads
Has-a relationship
question from Master Exam 3
Does HFSJ cover everything for a 100% score?
simple has-a question
Right view on questions