用java这么长时间了,对于static method 大家都知道在是怎么回事,但对nonstatic 的method()是不是每创建一个对象都会分配内存呢,google了一把,结果如下:
(1)。static method 永远只占用一块记忆体,而且此记忆体空间是在此class一被载入进记忆体之后就立刻配置的.
(2)。前面「不」加上static的修饰字,就会使得此method变成是instance method。
对instance method而言,每产生一个instance「并不会」多一块instance method的记忆体。
同一个method不管被调用(invoke)几次,也不管被调用时的instance是何者,每次的程式码完全都一样,
差别只在每次执行时资料不同,而资料是存放在call stack中,所以不会混淆。
在instance method内,资料的来源包括了参数和instance field。参数被传进来变成call stack内的entry,
所以不会混淆,这很容易理解,但是instance field是如何区隔开来的这是透过隐匿(implicit)的this参数来达
到了,一个有2个参数的函数,其实在后台是有3个参数的,其中一个就是存放this的变量
参考文章:http://www.moon-soft.com/doc/40702.htm ;http://www.moon-soft.com/doc/6214.htm
补充下:对于java的继承 内存机制: 在内存机制中,父类和子类是占用同一块内存的,只不过子类在父类的基础上增加了自己的部分(包括数据成员和属性),这样一来就好理解了。子类是依附于父类的,先有父类再有子类。所以说一个子类对象的产生,必须先调用父类的构造函数产生一个父类实例,然后在这个实例基础上添加自己的部分。 而实际的运行机制,也正是这样的。
分享到:
相关推荐
methode de simulation numerique du gsap
使用此 Dijkstra Methode,您可以找到图像的最短路径。 (见这里描述http://physingo-en.blogspot.de/2016/12/matlab-dijkstra-methode-large.html ) 函数[路径,上一个,无视,距离,开始,目标] = Dijkstra_...
Methode图像二进制映射器这是一个微服务,它侦听NativeCmsPublicationEvents Kafka主题,以供Methode发布事件并处理包含图像或pdf的消息。 它提取二进制文件,使用此信息创建消息,并将其写入CmsPublicationEvents...
Methode Electronics子公司dataMate Products新推出一款双端口小型可插拔(SFP) EMI笼屏蔽。该器件具有双重收发器和电磁干扰(EMI)保护功能,可保护光纤通道、千兆以太网及Infiniband等产品的铜及光SFP收发器。 ...
region growing methode in java
二分法 MN项目,java swing(图形界面)
FizzBuzz:Methode TDD
Fuzzy c-means (FCM) is an unsupervised clustering technique that has been successfully applied to feature analysis, clustering, and classification in the fields such as astronomy, geology
Considering the computational time complexity of the FCM clustering algorithm, the suppressed fuzzy clustering algorithms (S-FCM and MS-FCM) have been investigated where the main advantage is the ...
convolution using overlap add method
Methode_Pert_RO:方法和技巧的实施
Eine neuartige Methode zur Analyse kombinatorischer Substanzbibliotheken mittels paramagnetischer Reporter Eine neuartige Methode zur Analyse kombinatorischer Substanzbibliotheken mittels ...
方法e_p_Pollard
Methode newton Raphson for systeme eguation
Methode_classique_FG 编码分类法。横断面横向工程的证明,Polytech 4A浇铸FuturaGaïa企业。
ann load forecasting methode
methode des moments matlab
steganalysis by Es methode
steganography by dwt methode
steganographty by dct methode