

//構造函數求兩個點:1.他是一個與類同名的方法 2.沒有返回值類型,并沒有void修飾
public class Points{
int x,y;//(特征)
//構造函數的重載(行為)
Points(){
x=0;y=0;
}
Points(int a,int b){
x=a;y=b;
}
void show(){
System.out.println ("點的坐標是:("+x+","+y+")");
}
//實例化
public static void main (String[] args) {
Points Points1=new Points();//3.在創建對象時對他的成員變量進行初始化
Points Points2=new Points(3,4);
Points1.show();
Points2.show();
}
}
posted on 2009-03-26 09:19
鵬凌 閱讀(112)
評論(0) 編輯 收藏