• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

static members

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do static members reside in heap? if so which represents them? Does object of class Class represent them for each class written in Java
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I believe that all static member objects are allocated from the heap.
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As to the other part of your question - any instance of that class can reference the member by name:

EXAMPLE:
class Foo {
public static int i = 2;

public void myfunc () {
System.out.println ("i: " + i);
... OR ...
System.out.println ("i: " + this.i);
<= YOU'D ACCESS IT FROM INSIDE THE CLASS JUST LIKE
ANY OTHER MEMBER

Let's say we wanted to access this static member from *outside* the class. Then we could reference it by class name (instead of my class instance name).

EXAMPLE:
Foo f1 = new Foo ();
Foo f2 = new Foo ();

System.out.println ("the static member 'i' is: " + Foo.i);

'Hope that helps .. PSM
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic