• 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
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Master Exam Error

 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I think only the first option is correct.

-HAS-A relationships are always defined with instance variables

Read this for more details
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But what about this example? Do not all Honda Car will share a same HONDA logo?
What will you say this relationship?
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Me too
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So a right example could confuse peoples. Right na!!!

Please any sheriff or author clear this doubt :-(
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any official word on this?
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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....... :?:
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yup,

has-a relationship can exist for both instance and class variables. I couldn't find any official statements segregating the two though..
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 https://coderanch.com/t/269872/Programmer-Certification-SCJP/HASA#1253435



Maybe marc wanted us to search for it..........
 
author
Posts: 9050
21
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Happily living in the valley of the dried frogs with a few tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic