This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Static variables and methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static variables and methods" Watch "Static variables and methods" New topic

Static variables and methods

sudharani Savadi
Ranch Hand

Joined: Feb 23, 2011
Posts: 30

in java a static method can access only static data members but main() is a static method
still it is accessing the instance data members by creating an object of other class.
how can it be possible?"
Matthew Brown

Joined: Apr 06, 2010
Posts: 4541

It can only access static data members without an object reference. But if you've got an object reference, non-static members and methods can be accessed via that.


The distinction is that in non-static methods there is an implicit object reference (this), meaning you can access non-static members of the same object without a reference.

I'll move this to the Beginning Java forum, as it's more appropriate there.
sudharani Savadi
Ranch Hand

Joined: Feb 23, 2011
Posts: 30

Thank you.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Static variables and methods
It's not a secret anymore!