??????
???????Java???????????????????????????????????????????????????????????????????????????????????к???????????
??????????Robert Nielsen ????www.javaworld.com
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????java??????????????Щ??????????????????????????????潫????????? ???????????????Щ???????
????????????????
??????????????????????????????????????????????????????????????Platypus p1 = new Platypus();
??????????????????????????java??????
???????η??????????????????
?????????????????????????????????????η???????????????????????????????????????κη???????Σ? public?? protected?? private??????????Σ??????package ?? friendly?????. ????????????????????????????·????????????Σ? abstract?? final?? native?? static?? ???? synchronized??
?????????????????????????????????κ???????????????????void????????????з????????????void??
???????????????????????????ú?????????????????????????????????????????Сд??????????????????????д???????????????????????????????????????????????????????????????????????????????
????"this"???÷?
?????????????????ù????this?к???????????????this?????????з???????????????????????????this??????????????????????????????????this??????????????????????this??????????У?????????б????????????????????????????????
public class Platypus {
String name;
Platypus(String input) {
name = input;
}
Platypus() {
this("John/Mary Doe");
}
public static void main(String args[]) {
Platypus p1 = new Platypus("digger");
Platypus p2 = new Platypus();
}
}
???????????????У???2??????????б?????????????????????????????name???????????????????????????????????????????name??????? "John/Mary Doe".
????????????У???????ù????this?????????????????У????????????????????????????
????"super"???÷?
????????????????????ù????super???????????????????????????????????????б??????????е??????????????????
class Mammal {
void getBirthInfo() {
System.out.println("born alive.");
}
}
class Platypus extends Mammal {
void getBirthInfo() {
System.out.println("hatch from eggs");
System.out.print("a mammal normally is ");
super.getBirthInfo();
}
}
????????????????У????super.getBirthInfo()????ó???Mammal?б???????????
?????????????super????ó????е???????????????д????????????У?????????????????????????
????public class SuperClassDemo {
????SuperClassDemo() {}
????}
????class Child extends SuperClassDemo {
????Child() {
????super();
????}
????}
???????????????????????????????У??????? Child()?????? super??????????????????е??????SuperClassDemo???????????? Child???С?