Static methods are also known as class methods. A static method in a class can directly access other static members in the class. It cannot access instance members of the class, as there is no object being operated on when a static method is invoked. Note, however, that a static method in a class can always use a reference of the class's type to access its member, regargless of the whether these members are static or not.
How can static method access non static members? Thanks Barkat
Joined: Aug 03, 2002
Hi Barkat, if the static method is given (passed), or creates, an instance of it's class it can access the members of the class. That's how I interpret it anyway. Cheers, -Barry
Hi Barkat, Itz how we access the static variables in any main method. the following is an example. I think Khalid Mughal's book wants to say the same..
[ October 14, 2002: Message edited by: shweta mathur ]
--Shweta<br />SCJP 1.4 <br />SCWCD
Joined: Dec 12, 2001
I have 2000 publication of Khalid'd book. I'm starting to study for 1.4, please advise me if there is any new publication from KM for 1.4 Do the topics covered in this book except AWT and Swing are enough or do i have to refer more books Thanks.
Joined: Aug 14, 2002
Well if you have a static method, it can access static members (variables and methods) this we agree on, but what if it wants to access non-static members (instance members)? First instance members don't exist until an instance (object) of this class is created right? So for a static member to access an instance member, an instance of the class itself has to be created. Example:
Got the picture? [ October 14, 2002: Message edited by: Alfred Kemety ]