wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Member Variable. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Member Variable." Watch "Member Variable." New topic
Author

Member Variable.

Roll
Ranch Hand

Joined: Jan 20, 2000
Posts: 52
If you don't want a member variable of a class to be changed in any way then what would you do?
1) Make it private
2) Make it public
3) Make it final
4) Make it private and provide an accessor method that returns its value.
I think the answer could not be final because
Even you have declared member variable as final and you haven't intialized it you can intianlize it in constructor.
So, then answer cannot be final?
Can anybody else think what could be the posiible answer ?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20543
    ∞

So you want to have an unitialized value to be final and you cannot set to anything in the constructor? What would be the use of that?
I think "final" is the right answer. At the very least, this is its purpose.


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Luke Simon
Greenhorn

Joined: Jan 14, 2001
Posts: 14
The answer is final, because final variables must be initialized once and only once. A final variable is a constant. This means that it only has one value in its entire lifetime. Before initialization, it is not considered to have a value.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Roll .. welcome to JavaRanch
We have a Names Policy. Please read the document and re-register under a name that complies with the rules.
Thanks for your co-operation.
Jane


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
Consider Paul's rocket mass heater.
 
subject: Member Variable.