亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么輸出不了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();
		
	}
}	


正在回答

3 回答

?? public Test1(int i,int j){
???????? this.i = i;
???????? this.j = j;
??? }

1 回復 有任何疑惑可以回復我~
#1

qq_鉛筆上的蝸牛_04351142

你要將局部變量的值賦給成員變量,用this指針 當然為了你好理解 你可以這樣寫: public Test1(int a,int b){ this.i = a; this.j = b; }
2017-07-30 回復 有任何疑惑可以回復我~
#2

qq_Sun丶_2 提問者

非常感謝!
2017-07-30 回復 有任何疑惑可以回復我~

剛剛學的,改構造方法里的int i,int j都是形參,要用指針。

0 回復 有任何疑惑可以回復我~

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();

?????????

????}

} ?


1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么輸出不了i和j的值 構造方法里面的值不是已經賦值了嗎 為什么方法里不可以拿來用

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號