the var "maxElements" in class "Use" is declared "static", but here ,it's used in this method "this.maxElements", does it belong to a class not a object?
I tried it,and it did compile and run correctly
why???
Brij Garg
Ranch Hand
Joined: Apr 29, 2008
Posts: 234
posted
0
this.maxElements = maxElements;
At the time of compilation compiler will treat this statement as Use.maxElement. Static variables are always class variables.
Ben Smither
Greenhorn
Joined: Sep 09, 2008
Posts: 4
posted
0
Java allows to use a reference to an object instance to refer static variables and methods. The this in the constructor is the same as an object reference "useA" in the example as follows. Use useA = new Use(); useA.maxElements = 100;
Originally posted by zhu weitao: code about:
the var "maxElements" in class "Use" is declared "static", but here ,it's used in this method "this.maxElements", does it belong to a class not a object?
I tried it,and it did compile and run correctly
why???
Nabila Mohammad
Ranch Hand
Joined: Nov 05, 2007
Posts: 661
posted
0
You just cannot use "this" or "super" within Static methods. It will give a compiler error. [ September 11, 2008: Message edited by: Nabila Mohammad ]
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Brij Garg
Ranch Hand
Joined: Apr 29, 2008
Posts: 234
posted
0
Java allows to use a reference to an object instance to refer static variables and methods. The this in the constructor is the same as an object reference "useA" in the example as follows. Use useA = new Use(); useA.maxElements = 100;
java allow us to use objects to refer to static variables and methods. But we should not use objects references to refer to statics..... At compilation time object references get repleces with class name.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.