Originally posted by Burkhard Hassel:
Hi ranchers,
raunak saxena posted November 14, 2006 09:27 AM
hi dear,
(...)
hence you get an error massage (...)
Yeah, an error massage, that's what we need now!
To Jothi:
Yours,
Bu.
class Base{
protected int nsf1;
}
class TLCWithLocalClass extends Base{
private int nsf1;
void nonStaticMethod(final int p){
int f3 = p;
class NonStaticLocal extends Base{
//double ff = nsf1; //This is ok
double ff = TLCWithLocalClass.this.nsf1; //This is ok...(1)
}
}
static void staticMethod(){
class StaticLocalClass extends Base{
double gg = TLCWithLocalClass.this.nsf1; //This is not ok...WHY??(2)
}
}
}
(1) This is ok because class is defined within a method that is non static so it's an Inner class and has an implicit reference of Outer class(TLCWithLocalClass) so it can use it's variable even directly.
(2) This is not ok because class is defined within a method that is static which causes this class to be static implicitely which has no notion of outer class or "this" hence you get an error massage saying "non-static variable this cannot be referenced from a static context".
Mr. Bu.....
you guys never try to understands the logical thing instead tries to find bug always.
i was perfectly correct but the it was the printing mistake now see the code and let me know whether you understand or not.
regards