• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static method(function) compare between C++ and Java

 
Karma Police
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is said that no matter how many copies there are of a C++ class,there is only one copy of a static function of the class in the memory.
Does java have the same specifiction about static method or field?
------------------
Java Lover From Hell!
 
Ganesh Ram
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To clarify:
You normally only have one copy of a class in memory, but multiple instances (objects) of it. All these objects share the same definition of the methods, only the data (nonstatic fields and local varibles) need to be separated.
 
Metal Zhang
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,I got it understood.Thank you all!
Originally posted by Ilja Preuss:
To clarify:
You normally only have one copy of a class in memory, but multiple instances (objects) of it. All these objects share the same definition of the methods, only the data (nonstatic fields and local varibles) need to be separated.


------------------
Java lover from hell!
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The static fields are only shared between the objects from a class loaded by a class loader. If two class loaders load the same class twice, there are two copies of the static fields of the class.
Ted Neward has a Statics.pdf that descibes that, but I am not able to find it in javageeks.com
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic