regading static

hello all,

can we call Static method or variable by using reference variable.....( i know that it is available to all calsses before we run the program..) but in some books writen that we can... and its an programming tricks... i didn't understand this can any one pleas explain how it be ... with a example... please

[331 byte] By [sricharana] at [2007-11-27 9:22:46]
# 1
You can. 30 seconds with the compiler would have told you that.It makes no difference whether you call a static method with the class name or an instance of the class.
ejpa at 2007-7-12 22:17:26 > top of Java-index,Java Essentials,Java Programming...
# 2
Although, if you use an IDE it will give you a warning for it.
floundera at 2007-7-12 22:17:26 > top of Java-index,Java Essentials,Java Programming...
# 3
hello ejp, thanks for quick response....i just want if it is allready available why we call ...... what is the use....
sricharana at 2007-7-12 22:17:26 > top of Java-index,Java Essentials,Java Programming...
# 4

> i just want if it is allready available why we call

Eh?

> ...... what is the use....

You have an object which tells you the class, so the call still makes sense; the compiler can figure out what you mean; sometimes it might be handy not to have to distinguish between static and instance methods (e.g. when generating code). It doesn't cause any problems. Why wouldn't the language support it?

C++ works the same in this respect.

ejpa at 2007-7-12 22:17:26 > top of Java-index,Java Essentials,Java Programming...