|
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
1
,看一下下面程序错误发生在哪一行!
class
Test
implements
Runnable{
public
void
run(Thread t){
}
}
2
,输出结果是什么?
class
Test{
public
static
void
main(String[] args){
new
Thread(
new
Runnable(){
public
void
run(){
System.out.println(
"runClass run!"
);
}
}){
public
void
run(){
System.out.println(
"subClass run!"
);
}
}.start();
}
}
3
,输出结果是什么?
class
Test{
public
static
void
main(String[] args){
new
Thread(
new
Runnable(){
public
void
run(){
System.out.println(
"runClass run!"
);
}
}){
}.start();
}
}
一.
ProduceConsumeDemo.java:
1
: 错误: Test不是抽象的, 并且未覆盖Runnable中的抽象方法run()
class
Test
implements
Runnable{
^
1
个错误
二.
subClass run!
三.
runClass run!
(第二,三题,怎么说呢,匿名内部类得到的是其子类的对象!如果子类重写了父类的方法,那么一定调用的是子类的!否则就掉用父类的方法!)
|
本文转自 小眼儿 博客园博客,原文链接:http://www.cnblogs.com/hujunzheng/p/3923047.html,如需转载请自行联系原作者