已有101人关注
Constants_A和Constants_B报错,不知如何修改
发表在Java图书答疑 2020-08-20 悬赏:2 学分 《Java从入门到精通(第4版)》第17章 枚举类型与泛型
是否精华
版块置顶:

package worry;

interface Constants{

public static final int Constants_A=1;

public static final int Constants_B=12;//将常量放置在接口

}

public class ConstantsTest {

enum Constants2{

Constants_A,Constants_B

}

//使用接口定义常量

public static void doit(int c) {

switch(c) {

case Constants.Constants_A;

System.out.println("doit() Constants_A");

break;

case Constants.Constants_B;

System.out.println("doit() Constants_B");

break;

}

}

public static void doit2(Constants2 c) {

switch(c) {

case Constants_A;

System.out.println("doit2() Constants_A");

break;

case Constants_B;

System.out.println("doit2() Constants_B");

break;

}

}

public static void main(String[] args) {

ConstantsTest.doit(Constants.Constants_A);

ConstantsTest.doit2(Constants2.Constants_A);

ConstantsTest.doit2(Constants2.Constants_B);

ConstantsTest.doit(3);

}

}


分享到:
精彩评论 3
根号申
学分:4736 LV12
TA的每日心情
2021-07-16 23:48:46
2020-08-21
沙发

给出报错提示截图,以后你再这样瞎粘一堆代码,也不说啥问题,我就忽略你的所有帖子

Hanoch
学分:651 LV6
2020-08-25
板凳

嗯这里是冒号,不是分号

オタクは楽しい_1596010351
学分:222 LV4
2020-08-25
地板

Hanoch 发表于2020-08-25 15:37

嗯这里是冒号,不是分号

谢谢兄弟

首页上一页 1 下一页尾页 3 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照