aspose file tools*
The moose likes Java in General and the fly likes static method(function) compare between C++ and Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static method(function) compare between C++ and Java" Watch "static method(function) compare between C++ and Java" New topic
Author

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

Karma Police
Greenhorn

Joined: Aug 23, 2001
Posts: 11
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!


Java Lover From Hell!
Ganesh Ram
Ranch Hand

Joined: Jul 20, 2001
Posts: 33
Yes
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Metal Zhang
Ranch Hand

Joined: Aug 05, 2001
Posts: 52
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!


Java lover from hell!
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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


SCJP2. Please Indent your code using UBB Code
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: static method(function) compare between C++ and Java
 
Similar Threads
EL Question
Interesting question from javacross!
What are virtual functions ?
static variable inside function definition
Function Outside the Class