Overriding

王朝百科·作者佚名  2010-02-14  
宽屏版  字体: |||超大  

Overriding :重写

Overriding 是指子类有一个函数与父类中的某个虚函数的名字和签名都相同。当一个子类的对象调用该虚函数时,就会执行子类中Overriding 的那个函数。所以Overriding 改变的是类的行为而不是类的接口。

Overriding:

Signature has to be the same. (including the return type)Overriding methods cannot be more private than the overridden methods.Overriding methods may not throw more checked exceptions than the overridden methods. But can throw no exception.Related directly to sub-classing. Overrides the parent class method. Resolved at run-time based on type of the object.Overriding method can call overridden method by super.methodName(), this can be used only to access the immediate super-class’s method.super.super won’t work. Also, a class outside the inheritance hierarchy can’t use this technique.

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有