資源簡介
java高級,源碼,ppt,學習好資料...
代碼片段和文件信息
class?Point{
private?object?x?; //?表示X坐標
private?object?y?; //?表示Y坐標
public?void?setX(object?x){
this.x?=?x?;
}
public?void?setY(object?y){
this.y?=?y?;
}
public?object?getX(){
return?this.x?;
}
public?object?getY(){
return?this.y?;
}
};
public?class?GenericsDemo01{
public?static?void?main(String?args[]){
Point?p?=?new?Point()?; //?聲明一個Point的對象
p.setX(10)?; //?利用自動裝箱操作:int?-->?Integer?-->?object
p.setY(20)?; //?利用自動裝箱操作:int?-->?Integer?-->?object
int?x?=?(Integer)p.getX()?; //?取出數據先變為Integer,之后自動拆箱
int?y?=?(Integer)p.getY()?; //?取出數據先變為Integer,之后自動拆箱
System.out.println(“整數表示,X坐標為:“?+?x)?;
System.out.println(“整數表示,Y坐標為:“?+?y)?;
}
};
- 上一篇:mqtt詳細
- 下一篇:javaWeb天下陶網絡商城SSH項目源碼
評論
共有 條評論