词条 | Overriding |
释义 | 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. |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。