Java?е???????????
???????????? ???????[ 2014/12/29 11:39:26 ] ????????Java ??????? ?????
????????????????д
??????????????е???????Caller???д???call????????????????????????SubCaller????Caller??????д???????????????????????????????????????????????
????????????????????????????????ò????String?????call???????????????????ж????????????????????call????
public class TestMain {
public static void main(String[] args) {
String str = new String();
Caller callerSub = new SubCaller();
callerSub.call(str);
}
static class Caller {
public void call(Object obj) {
System.out.println("an Object instance in Caller");
}
public void call(String str) {
System.out.println("a String instance in in Caller");
}
}
static class SubCaller extends Caller {
@Override
public void call(Object obj) {
System.out.println("an Object instance in SubCaller");
}
@Override
public void call(String str) {
System.out.println("a String instance in in SubCaller");
}
}
}
??????н???
????22:30 $ java TestMain
????a String instance in in SubCaller
???????
?????????????????????????????·?????????
22:30 $ javap -c TestMain
Compiled from "TestMain.java"
public class TestMain {
public TestMain();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: new #2 // class java/lang/String
3: dup
4: invokespecial #3 // Method java/lang/String."<init>":()V
7: astore_1
8: new #4 // class TestMain$SubCaller
11: dup
12: invokespecial #5 // Method TestMain$SubCaller."<init>":()V
15: astore_2
16: aload_2
17: aload_1
18: invokevirtual #6 // Method TestMain$Caller.call:(Ljava/lang/String;)V
21: return
}
????????????
?????????????????
???????????????Щ??????????????????????????
????public static void main(String[] args) {
????String str = new String();
????final Caller callerSub = new SubCaller();
????callerSub.call(str);
????}
????????????callerSub????subCaller???????callerSub?????final???????????call??????????????????????????????????????????????SubCaller??call??????
?????????????н??о???????
?????????????Caller?????????????BaseCaller?????????call????????BaseCaller?????SuperCaller??SuperCaller?ж?call???????????????
????????????1.0?е?BaseCaller??SuperCaller
static class SuperCaller {
public void call(Object obj) {
System.out.println("an Object instance in SuperCaller");
}
}
static class BaseCaller extends SuperCaller {
public void call(Object obj) {
System.out.println("an Object instance in BaseCaller");
}
}
???????????????1.0????????????????Caller?????BaseCaller???????????super.call??????
public class TestMain {
public static void main(String[] args) {
Object obj = new Object();
SuperCaller callerSub = new SubCaller();
callerSub.call(obj);
}
static class Caller extends BaseCaller{
public void call(Object obj) {
System.out.println("an Object instance in Caller");
super.call(obj);
}
public void call(String str) {
System.out.println("a String instance in in Caller");
}
}
static class SubCaller extends Caller {
@Override
public void call(Object obj) {
System.out.println("an Object instance in SubCaller");
}
@Override
public void call(String str) {
System.out.println("a String instance in in SubCaller");
}
}
}
?????????????????????1.0??????????class????????農(nóng)??????????????Caller??super.call?BaseCaller.call????
?????????????μ?????????1.1?汾??BaseCaller????дSuperCaller??call??????????????????????????call?????1.1?汾??????????????1.1?汾??super.call????????SuperCall??call?????????????????t?????????BaseCaller??call????????
???????????Щ??????????????????????????????????????????????
?????????????????
????????????????????????????????汾?????????????????????????????????
???????????????????????????????????????????????private??static????final???????Ρ?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11