• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A quote from Khalid A. Mughal

 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quote from page 121:


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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic