为什么会报错?谢谢

为什么会报错?谢谢

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
56
57
58
package com.imooc.CSDM;
 
interface One{
    final int x = 11;
}
 
interface Two{
    final int x = 22;
}
 
class Tree{
    public int x = 33;
}
 
public class TestOne implements One,Two{
    public void test(){
         
        //无法判断是执行one当中的x 还是 执行two中的x;
        //System.out.println(x);
        //修改:
        System.out.println(One.x);
        System.out.println(Two.x);
    }
     
    public static void main(String[] args) {
        new TestOne().test();
 
    }
 
}
 
package com.imooc.CSDM;
 
interface One{
    final int x = 11;
}
 
interface Two{
    final int x = 22;
}
 
class Tree{
    public int x = 33;
}
 
public class TestTwo implements One,Two{
    public int x = 44;
    public void test(){
         
        System.out.println(x);
    }
     
    public static void main(String[] args) {
        new TestOne().test();
 
    }
 
}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕雪 2017-10-12 18:27:54

没出错呀!哪错了?你想问什么?如果我理解错了,请你仔细描述一下你想问的问题。祝:学习愉快

  • 提问者 宝慕林7867458 #1
    在TestTwo类中,One,Two,Tree前面都会出现一个红色的错号,这是怎么回事呀?
    2017-10-13 10:34:36
  • irista23 回复 提问者 宝慕林7867458 #2
    同名了,在同一个包下不能建两个同名的类或接口
    2017-10-13 15:45:09
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码