This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Static in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static in Java" Watch "Static in Java" New topic
Author

Static in Java

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hey i have read Somewhere...

"The rule is, a static method of a classs can't access a nonstatic(instance) method or varaible of its own"

Does it mean that that staic mathod can access nonstatic(instance) method or variable of other...

One more Doubt:

i can declare nonstatic variable in static method an I right?
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710
hi Jay,

Statement is correct. Static method can't access non static member
variables, because inside static method there is no "this" reference

Did you try that?


method or variable of other...


Other means, is that practically tried by you.


cmbhatt
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi Chandra , Yes, i have tried. And it succcessfully worked.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44563
    
  34
And you can't create static or "non-static" (probably better called "instance") variables in a static method; you can only create local variables.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static in Java
 
It's not a secret anymore!