为了账号安全,请及时绑定邮箱和手机立即绑定

java非法的表达式开始

java非法的表达式开始

人到中年有点甜 2018-10-10 13:28:15
public class Main{public static void main(String args[]){ private int a = 1; int b =2; protected int c = 3; public int d = 4; System.out.println(a+" "+b+" "+c+" "+d); }}
查看完整描述

1 回答

?
浮云间

TA贡献1829条经验 获得超4个赞

public class Main {

public static void main(String[] args) {
/**
 * 这里面不应该有private这种限定符
 */
private int a = 1;
int b = 2;
protected int c = 3;
public int d = 4;
System.out.println(a + " " + b + " " + c + " " + d);
}

}

改写如下


public class Main {

private int a = 1;
int b = 2;
protected int c = 3;
public int d = 4;

public static void main(String[] args) {

Main m = new Main();
m.display();
}

private void display() {
System.out.println(a + " " + b + " " + c + " " + d);
}

}

或者

public class Main {

private static int a = 1;
static int b = 2;
static protected int c = 3;
static public int d = 4;

public static void main(String[] args) {

System.out.println(a + " " + b + " " + c + " " + d);
}

}
查看完整回答
反对 回复 2018-10-24
  • 1 回答
  • 0 关注
  • 2622 浏览

添加回答

举报

0/150
提交
取消
微信客服

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

帮助反馈 APP下载

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

公众号

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