為什么輸出不了i和j的值 構造方法里面的值不是已經賦值了嗎 為什么方法里不可以拿來用
public?class?Test{ int?i; int?j; public?Test(int?i,int?j){ } public?void?show(){ System.out.println(i+j); } public?static?void?main(String[]?args){ Test?hello=new?Test(1,24); hello.show(); } }
public?class?Test{ int?i; int?j; public?Test(int?i,int?j){ } public?void?show(){ System.out.println(i+j); } public?static?void?main(String[]?args){ Test?hello=new?Test(1,24); hello.show(); } }
2017-07-30
舉報
2017-07-30
?? public Test1(int i,int j){
???????? this.i = i;
???????? this.j = j;
??? }
2017-07-30
剛剛學的,改構造方法里的int i,int j都是形參,要用指針。
2017-07-30
public?class?Test{
????int?i;
????int?j;
????public?Test(int?i,int?j){
? ? ? ? ?this.i=i;
????????this.j=j;
????}
????public?void?show(){
?????????
????????System.out.println(i+j);
????}
????public?static?void?main(String[]?args){
????????Test?hello=new?Test(1,24);
????????hello.show();
?????????
????}
} ?