小编Dee*_*rma的帖子

为什么我不能在java构造函数中使用静态变量?

编译说illegal modifier for parameter i.
请告诉我我做错了什么.为什么我不能在Java构造函数中使用静态变量?

class Student5{  

    Student5() {  
        static int i = 0;
        System.out.println(i++);  
    }

    public static void main(String args[]){  
        Student5 c1 = new Student5();
        Student5 c2 = new Student5();
        Student5 c3 = new Student5();
    }
}  
Run Code Online (Sandbox Code Playgroud)

java static constructor static-variables

1
推荐指数
1
解决办法
6000
查看次数

标签 统计

constructor ×1

java ×1

static ×1

static-variables ×1