java中的所有方法都是隐含的虚拟 [英] Are all method in java implictly virtual
问题描述
如果java中没有编译时绑定,这是否意味着所有绑定都是在运行时完成的?
但是根据运行时绑定的OOP概念,函数必须具有virtual keyword..ARE所有方法在java中隐式虚拟或java中是否存在任何编译时绑定
如果有任何编译时绑定,你能否给我一些具体的情况,或更多信息的链接
- 静态(此处没有绑定的含义,因为静态不属于对象)
- final(这不是一个有效点,因为它可以用另一种方式获得)
所有非静态
,非最终
和非私有
方法在Java中默认是虚拟的。但是,JVM足够聪明,只能找到只有一个给定方法实现的类,并将其转换为静态绑定。
这样你就不必记住虚拟
关键字(由于在C ++中的析构函数中缺少虚拟
而经历过内存泄漏?),而性能不会受到太大影响。 / p>
If there are no compile time binding in java, do this mean all binding are done at runtime?
But as per OOPs concept for runtime binding, functions must have virtual keyword..ARE all methods implicitly virtual in java or is there any compile time binding exist in java
If there is any compile time binding, can you give me some specific situation, or links to further information
- Static (There is no meaning of binding here as static does not belongs to object)
- final (this is not a valid point as it can be achived in another way)
All non-static
, non-final
and non-private
methods are virtual by default in Java. However JVM is clever enough to find classes having only one implementation of given method and turn it into static binding.
This way you don't have to remember about virtual
keyword (ever experienced memory leak due to missing virtual
on destructor in C++?) while the performance is not impacted that much.
这篇关于java中的所有方法都是隐含的虚拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!