??????java????—–?????????ж????????????????????????????????????????????????????????????????????????????????????????????????????á????????????????????γ???????????????????????????β??????final??
????????????????????????
????????????????????????????????????????е????????????????£?
????new ???????????????б??|??????????
????{
????//?????????????巋??
????}
??????????????????????????????????????????????????????????????????????????????????????????????????????class??????????????????????????????new??????????????????á???????????????????
public abstract class Bird {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public abstract int fly();
}
public class Test {
public void test(Bird bird){
System.out.println(bird.getName() + "????? " + bird.fly() + "??");
}
public static void main(String[] args) {
Test test = new Test();
test.test(new Bird() {
public int fly() {
return 10000;
}
public String getName() {
return "????";
}
});
}
}
------------------
Output??
????????? 10000??
??????Test???У?test()???????????Bird????????????????????????????????а????new???????????????????????new????????????????????????mian??????????????????????????????Bird?????
?????????????????????????????????????????????????????????????е????????
???????????????????????????????????????????
????public class WildGoose extends Bird{
????public int fly() {
????return 10000;
????}
????public String getName() {
????return "????";
????}
????}
????WildGoose wildGoose = new WildGoose();
????test.test(wildGoose);
????????????????????????Bird????????????????????????Bird????????á?
??????????????????????????????????????????????????Σ????????????????????????????????????????????????????????????????????????????????????á???????????????????????????test()???????????????ж?????????????????????????????????????
???????????????
???????????????????????У??????????????????
????1??????????????????????????????????????????????????????????????????????????????????????
????2????????????????????幹???????
????3????????????в???????κε????????????????????
????4????????????????????????????????????????????????????????Ч??
????5???????????????????????????????е????????????????г???????