class Pt3DCls{
//インスタンス変数
double x, y, z;
String Name;
boolean Flag;
//コンストラクタ
Pt3DCls(){
/*
* 各インスタンス変数が、規定値に初期化される。
* x, y, zが0、Nameが"null"、Flagがfalseになる。
*/
}
Pt3DCls(double x){
this(x, x * 10, x * 20);
}
Pt3DCls(double x, double y){
this(x, y, x * 2);
}
Pt3DCls(double x, double y, double z)
{
Name = new String();
Name = "temp";
Flag = true;
this.x = x;
this.y = y;
this.z = z;
}
//インスタンスメソッド
void Move(double dDt){
this.x += dDt;
this.y += dDt;
this.z += dDt;
Name += "_Move";
}
}
public class Test_INS {
public static void main(String[] args) {
System.out.println("Start");
//
System.out.println("------------------------");
//
System.out.println("////// p1 /////");
Pt3DCls p1 = new Pt3DCls();
System.out.println("Name = " + p1.Name + "//");
System.out.println("Flag = " + p1.Flag);
System.out.println("x = " + p1.x);
System.out.println("y = " + p1.y);
System.out.println("z = " + p1.z);
System.out.println("");
//
System.out.println("////// p1 Move /////");
p1.Move(15.0);
System.out.println("Name = " + p1.Name + "//");
System.out.println("Flag = " + p1.Flag);
System.out.println("x = " + p1.x);
System.out.println("y = " + p1.y);
System.out.println("z = " + p1.z);
System.out.println("");
//
System.out.println("////// p2 /////");
Pt3DCls p2 = new Pt3DCls(1.0);
System.out.println("Name = " + p2.Name + "//");
System.out.println("Flag = " + p2.Flag);
System.out.println("x = " + p2.x);
System.out.println("y = " + p2.y);
System.out.println("z = " + p2.z);
System.out.println("");
//
System.out.println("////// p2 Move /////");
p2.Move(15.0);
System.out.println("Name = " + p2.Name + "//");
System.out.println("Flag = " + p2.Flag);
System.out.println("x = " + p2.x);
System.out.println("y = " + p2.y);
System.out.println("z = " + p2.z);
System.out.println("");
//
System.out.println("////// p3 /////");
Pt3DCls p3 = new Pt3DCls();
p3.Name = new String(); //Name変数を初期化
System.out.println("Name = " + p3.Name + "//");
System.out.println("Flag = " + p3.Flag);
System.out.println("x = " + p3.x);
System.out.println("y = " + p3.y);
System.out.println("z = " + p3.z);
System.out.println("");
//
System.out.println("////// p3 Move /////");
p3.Move(15.0);
System.out.println("Name = " + p3.Name + "//");
System.out.println("Flag = " + p3.Flag);
System.out.println("x = " + p3.x);
System.out.println("y = " + p3.y);
System.out.println("z = " + p3.z);
System.out.println("");
//
System.out.println("------------------------");
System.out.println("End");
}
}
|