File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -799,6 +799,36 @@ Java 程序设计语言对对象采用的不是引用调用,实际上,对象
799799- “两小”指的是子类方法返回值类型应比父类方法返回值类型更小或相等,子类方法声明抛出的异常类应比父类方法声明抛出的异常类更小或相等;
800800- “一大”指的是子类方法的访问权限应比父类方法的访问权限更大或相等。
801801
802+ ⭐️ 关于 ** 重写的返回值类** 型 这里需要额外多说明一下,上面的表述不太清晰准确:如果方法的返回类型是void 和基本数据类型,则返回值重写时不可修改。但是如果方法的返回值是引用类型,重写时是可以返回该引用类型的子类的。
803+
804+ ```java
805+ public class Hero {
806+ public String name () {
807+ return " 超级英雄" ;
808+ }
809+ }
810+ public class SuperMan extends Hero {
811+ @Override
812+ public String name () {
813+ return " 超人" ;
814+ }
815+ public Hero hero () {
816+ return new Hero ();
817+ }
818+ }
819+
820+ public class SuperSuperMan extends SuperMan {
821+ public String name () {
822+ return " 超级超级英雄" ;
823+ }
824+
825+ @Override
826+ public SuperMan hero () {
827+ return new SuperMan ();
828+ }
829+ }
830+ ```
831+
802832#### 1.4 . 4. 深拷贝 vs 浅拷贝
803833
8048341. ** 浅拷贝** :对基本数据类型进行值传递,对引用数据类型进行引用传递般的拷贝,此为浅拷贝。
You can’t perform that action at this time.
0 commit comments