开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜