76.类的重载(Overloading)和重入(Overriding)
重入方法(method)
要重入一个 method, 最早定义这个method的类的一个子类必须用同样的名字, 返回类型, 和参数表定义一个method.
当该method 被该子类的一个实例调用时, 这个新的 method 将被调用, 而不是原来的那个 method.
被重入的method 可以用super变量调用.
Super 也可以用于指向父类中中的实例变量.
重载方案是基于被称为 Method签名的技术来实现的 (参见 Arnold-Gosling 的书) :
参数表最低转换代价, 基于类型和数目.
返回类型和描述顺序是不重要的.
Java will declare an error if method is invoked where there is not one with a unique signature which matches call after removing less specific methods (use of objects in hierarchy can cause lots of confusing matches!)
Copyright: NPACT