原來的面貌:
1
2
3
4
5
6
7
8
|
class TT extends Test{ void show() { System.out.println(s+ "~~~哈哈" ); System.out.println( "超級女聲" ); } TT tt= new TT(); tt.show(); |
只是說我們這里采用的是匿名的形式來處理.
重寫了Test的show()方法,在重寫好了以后,又調(diào)用了重寫后的show()方法
實(shí)現(xiàn)代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package cn.com; class Test { String s = "春哥萬歲!" ; public void show(Test t) { System.out.println( "信春哥,得永生" ); } } class Outer { int x = 23 ; int i = 12 ; public void method() { new Test() { //匿名內(nèi)部類 void show() { //重寫show()方法 System.out.println(s+ "~~~哈哈" ); System.out.println( "超級女聲" ); } }.show(); } } class TestInner { public static void main(String[] args) { new Outer().method(); } } |
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
原文鏈接:http://blog.csdn.net/lfdfhl/article/details/8195061