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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

正在回答

3 回答

這個(gè)是書上的一個(gè)例子看懂了就?

0 回復(fù) 有任何疑惑可以回復(fù)我~
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 回復(fù) 有任何疑惑可以回復(fù)我~

Java調(diào)用private方法利用的是Java中的類反射機(jī)制 。
定義一個(gè)class,定義一個(gè)內(nèi)部private方法:
public class PrivateTest {
private void print() {
System.out.println("this is a private method");
}
}
再定義一個(gè)class去訪問(wèn)剛才定義的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的反射機(jī)制,即使是private方法,也可以被調(diào)用使用。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門第二季
  • 參與學(xué)習(xí)       531371    人
  • 解答問(wèn)題       6327    個(gè)

課程升級(jí)!以終為始告別枯燥,在開(kāi)發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙

進(jìn)入課程
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)