第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

正在回答

3 回答

這個是書上的一個例子看懂了就?

0 回復 有任何疑惑可以回復我~
public?class?Student?{	private?String?stuno;	private?String?name;	private?float?math;	private?float?english;	private?float?computer;	public?Student()?{	}	public?Student(String?stuno,String?name,float?math,float?english,float?computer)?{		this.setStuno(stuno);		this.setName(name);		this.setMath(math);		this.setEnglish(english);		this.setComputer(computer);	}	public?void?setStuno(String?s)?{		stuno?=?s;	}	public?void?setName(String?n)?{		name?=?n;	}	public?void?setMath(float?m)?{		math?=?m;	}	public?void?setEnglish(float?e)?{		english?=?e;	}	public?void?setComputer(float?c)?{		computer?=?c;	}	public?String?getStuno()?{		return?stuno;	}	public?String?getName()?{		return?name;	}	public?float?getMath()?{		return?math;	}	public?float?getEnglish()?{		return?english;	}	public?float?getComputer()?{		return?computer;	}	public?float?sum()?{		return?math+english+computer;	}	public?float?avg()?{		return?this.sum()/3;	}	public?float?max()?{		float?max?=?math;		max?=?max?>?computer?max:computer;		max=max>english?max:english;		return?max;	}	public?float?min()?{		float?max?=?math;		max?=?max?<?computer?max:computer;		max=max<english?max:english;		return?max;	}};


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

Java調用private方法利用的是Java中的類反射機制 。
定義一個class,定義一個內部private方法:
public class PrivateTest {
private void print() {
System.out.println("this is a private method");
}
}
再定義一個class去訪問剛才定義的private方法,也就是print()如下
import java.lang.reflect.Method;

public class PrivateTest2 {
public static void main(String[] args) {
try {
Method method = PrivateTest.class.getDeclaredMethod("print", new Class[]{});
method.setAccessible(true);
Method.invoke(new PrivateTest(), new Object[] {});
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}
利用java的反射機制,即使是private方法,也可以被調用使用。

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

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531098    人
  • 解答問題       6280    個

課程升級!以終為始告別枯燥,在開發(fā)和重構中體會Java面向對象編程的奧妙

進入課程

求講解,老師

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

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號