Do objects of one class share code
If there is a class A and I instantiate three objects x,y,z of A, and there is a function foo() in A, then will three copies of machine code exist for f (one for each object)?
What is the purpose of class methods? When all objects h开发者_开发百科ave shared code why use class methods anyway? Is it just an abstraction to an HLL programmer?
No, there won't. There will be only one copy of the code. Each class instance will however have its own copies of the class's member variables.
You also asked about Class Methods which are also known as Static methods.
In this case there is still only one copy of the code but when executed it can only modify static members, which all instances of the class (the objects) will see.
精彩评论