• 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 question about static

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the only thing i know about static is that if we
make a method outsite in another class
we can accses this method without making constructor

my question is
when i define a staic variable and a normal variable
a static method and a non static method

what type of variable each type of method can see?
or what about accessing static methods
instead of variables as in the previos question
what accses do we have??
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static members:-
  • Are loaded into memory when the particular class is loaded.
  • Stay put in memory (hence the word static), although a GC can rearrange all the memory.
  • Go with the class, so should be called by MyClass.itsStaticMember
  • A class has one copy of each static member
  • Each instance of the class has one copy of each non-static (better called instance) field
  • Access to static members is controlled just as for instance members: public private [default] or protected
  • Every instance of a class has access to all its private static members, but remember there is only ever one copy of each, so they all access the same memory location
  • Public static members can be imported into other classes with import static, then used as if they were static members of both classes
  • Static members are in existence and accessible before any instances have been created
  • Because the static members are in memory before the instances are created, the static members cannot find out the memory locations of the instances, so static methods cannot access "non-static" (instance) members.I hope this all helps.

    CR

    [edit]Minor formatting corrections[/edit]
    [ December 30, 2007: Message edited by: Campbell Ritchie ]
     
    Ranch Hand
    Posts: 3389
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by johny doe:
    the only thing i know about static is that if we
    make a method outsite in another class
    we can accses this method without making constructor



    It should be "without making an instance". You don't make any constructor rather you define your constructor to make up your instance.
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3389
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This link will help you further.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic