my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Blank Finals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Blank Finals" Watch "Blank Finals" New topic
Author

Blank Finals

Jui Mahajan
Ranch Hand

Joined: Jun 02, 2003
Posts: 62
The Javaranch exam (roundup) has a question which says " Are instance (member) variables always initialized if they r not explicitly initialzed by the user ?" The ans given is yes. But I think that if an instance variable is a blank final variable, then it will always have to be explicitly initialized by the user, either in the declaration itself or in the constructor ..Pls clarify.
Also, this exam has one more question I am unsure about. The question says
" Can an object of a class access the private variables of another object of the same class ?" The given ans is yes. But I think that this will violate the very essence of Data hiding and encapsulation....so what is the explanation ? Also for that matter, can an object access any members (i.e including public members)of another object ?


-----jui<br />scjp1.4
Damien Howard
Ranch Hand

Joined: Apr 01, 2003
Posts: 456
Also, this exam has one more question I am unsure about. The question says
" Can an object of a class access the private variables of another object of the same class ?" The given ans is yes. But I think that this will violate the very essence of Data hiding and encapsulation....so what is the explanation ? Also for that matter, can an object access any members (i.e including public members)of another object ?

The access modifiers have to do with different classes not objects. Two objects of the same class can access each others members regardless of the access modifier.
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
If a final variable isn't initialized at the time of definition, it can't be assigned in a constructor. Therefore, it would be the default for that type, and immutable. I believe that the answer is correct.
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
Originally posted by Jui Mahajan:
But I think that if an instance variable is a blank final variable, then it will always have to be explicitly initialized by the user, either in the declaration itself or in the constructor ..Pls clarify.

I believe that the right word is definitely assigned. Blank instance final variables are still implicitly initialized but Java requires that they are definitely assigned at the end of the constructor.
You can see from this code that i is initialized to 0 before the start of Test13b constructor.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Blank Finals