Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Methods

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, if I have Class A and it contains 4 static methods.
Then lets say I have 4 more Classes, Class B, Class C, Class D, and Class E.
Now, if I instantiate Class A in B, C, D, and E is there still only 1 instance of each of the static methods in memory from Class A?
 
khella smith
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i suppose so because when once u have a static method in a class no matter how many instances of that class u have the method stays the same because it is only loaded once at compile time so i suppose the same would apply for instanciating class a in different class since that static method is in class a alone i suppose it will still stay the same
correct me if i am wrong
i'll appreciate it
----------------
khella smith
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods are not replicated per object.
Methods are kept in a special "method area" with the Classfile. Some of those methods are tracked as Static and some as member methods.
When a method is invoked the JVM ALWAYS goes to the classfile to find the code to execute. It is over in "classfile-land" that polymorphism takes place.
The only things that actually reside in an object are the variables that track state and a "type" identifier.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic