Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which of the Following is True?

 
Scott Hemsley
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and why?

a)Transient methods must be static.
b)Native methods violate Java�s platform independence.
c)Static methods cannot be protected.
d)Transient variables may not be final or static.

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, not to be too Rogerian about it, but... what do you think the answer is?
 
Scott Hemsley
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
d) But the person who assited me with the answer was unsure why?
He also suggested maybe b)
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say B, not D. Although a transient static or final variable may not make sense, it shouldn't be prohibited. Afterall, transient only really becomes important with persistance and serialization classes.

However, the native keyword quite obviously violates platform independence; it requires a dynamically loaded library to be written in native code. This library limits the platforms on which the Java program will work.
 
Scott Hemsley
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Hemsley:
and why?

a)Transient methods must be static.
b)Native methods violate Java�s platform independence.
c)Static methods cannot be protected.
d)Transient variables may not be final or static.

Thanks
The answer is b) and d).

I missed the instruction "Choose more than one" .

Thanks to those who responded.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why d?

This compiles with no problem.

 
Scott Hemsley
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know, I only got the answer not the explanation.

BTW, What is the purpose of Transient variables?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When an object of a Serializable class is written out to a file, any field marked transient will not have it's value stored as part of the object.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e) Boxcar Willy is a transient.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e) none of the above

However, there is a common misconception among the community that would compel many to suggest b), therefore, if you are in an exam, I would answer b) based simply on the fact that the misconceptions that lead to the other answers are less prolific and therefore, less likely.

This is exactly the principle that I used for SCJP 5.0 i.e. thinking in terms of "what Sun want me to think", not "what is correct". It is very important to distinguish between these two, especially where there is a commercial interest (e.g. reading a technical book, doing an industry exam) or plain general misunderstanding or a "sheep following" (e.g. academia).

I proclaim neutrality and no other agenda but to portray fact as best as possible (Goedel's incompleteness, that I am human, etc. withstanding), but that doesn't stop me from being wrong sometimes Only that I like being wrong, since it contributes to my objective as opposed to the impact of being wrong when there is some other agenda. I certainly know what the Java platform is though, since it was once (and no longer is yay!!) my job to implement the thing

Good luck.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Hemsley:
I don't know, I only got the answer not the explanation.

BTW, What is the purpose of Transient variables?


If they can't explain the answer then what good is it?
 
Scott Hemsley
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ken Blair:


If they can't explain the answer then what good is it?

OK.

I think the key to the answer d) is the wording.

d)Transient variables may not be final or static.

"May not be" not "Must not be". It is saying they don't have to be final or static.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure. I took it to mean that a transient variable could not also be declared static nor final.
 
Scott Hemsley
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Me too.

Thanks for your help, anyway.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want to feed on anyone's conspiracy theories but last night a Prius pulled past me and I could have sworn James Gosling was driving and that Dick Cheney was riding shotgun!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic