A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
is "this" a static variable ?
Joined: Jan 24, 2010
Aug 06, 2012 07:32:08
if i try to use this from my main it will say "this" is not a static variable.
when i have a inner class and want the reference of the outer class, i use OuterClassName.this to get the reference.
Is this scenario an exception ? is my understanding correct ?
Thanks & regards,
Joined: Apr 06, 2010
Aug 06, 2012 08:07:03
No, that's not a static variable. That's just a special syntax that allows you to get a reference to the enclosing class.
If it was a static variable, it would have the same value regardless of which object you were in, but it doesn't. It refers to the specific instance of
that contains the current object.
Joined: Jun 02, 2011
Aug 06, 2012 08:11:15
Instead use an object like this in your class
OtherClass instance = new OtherClass();
you can use the instance variable
I agree. Here's the link:
subject: is "this" a static variable ?
static key word
How to access another class having private constructor using it's static variavble ?
Using Variables From Another Object
Isn't this contradictory ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013