posted 22 years ago
This is from JLS 8.3.2.3 Restrictions on the use of Fields during Initialization
class UseBeforeDeclaration {
{
j = 200; // ok - assignment
j = j + 1; // error - right hand side reads before declaration
int k = j = j + 1;
int n = j = 300; // ok - j at left hand side of assignment
int h = j++; // error - read before declaration
int l = this.j * 3; // 1... ok - not accessed via simple name
Object o = new Object(){
void foo(){j++;} // ok - occurs in a different class
{ j = j + 1;} // ok - occurs in a different class
};
}
int j;
I have 2 questions
a)Is not line 1... is same as
int l = j * 3;
b)For instance method, accessing a instance variable implicitly use this for that object. Is that different in instance initializer ?
Please help me.
Ambapali