File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes doubt in static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt in static" Watch "doubt in static" New topic
Author

doubt in static

r suraaj
Greenhorn

Joined: Oct 26, 2008
Posts: 16
we can't access the instance variables inside the static method.,
but in main() method we can create new objects to the class and we can access the instances of the class.,

so my doubt is for main() method is it an exception??
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

r suraaj wrote:but in main() method we can create new objects to the class and we can access the instances of the class.,

Have you tried this in static method other than main() method?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
r suraaj
Greenhorn

Joined: Oct 26, 2008
Posts: 16
yes., i tried.,

other than main() method other static methods doesn't have the access to instance variables and non-static methods.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

r suraaj wrote:yes., i tried.,
other than main() method other static methods doesn't have the access to instance variables and non-static methods.

Main method is not behaving differently from other static methods, it's just the starting point where JVM looks for when running a class. Neither of them have access to the instance fields etc.., but as you said earlier by creating an instance it's possible to access that instance's fields either in normal static method or in main() method.
r suraaj
Greenhorn

Joined: Oct 26, 2008
Posts: 16
thank you Vijitha Kumara for your reply.,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in static