aspose file tools
The moose likes Beginning Java and the fly likes is Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "is "this" a static variable ?" Watch "is "this" a static variable ?" New topic
Author

is "this" a static variable ?

Preet Dholabhai
Greenhorn

Joined: Jan 24, 2010
Posts: 19
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,
Preet
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3786
    
    1

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 OuterClassName that contains the current object.
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 77

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: http://aspose.com/file-tools
 
subject: is "this" a static variable ?
 
Similar Threads
static key word
definitions
How to access another class having private constructor using it's static variavble ?
Using Variables From Another Object
Isn't this contradictory ?