class aabb{
public static void main(String args[]){
hensuu hen_obj=new hensuu();
stati st_obj1=new stati();
stati st_obj2=new stati();
consto co_obj1=new consto();
consto co_obj2=new consto(100);
over ov_obj=new over();
seigen sei_obj=new seigen();
hen_obj.Demo();
st_obj1.add(20);
st_obj2.add(100);
co_obj1.add(30);
co_obj2.add(30);
System.out.println("st_obj1 = " + st_obj1.tota);
System.out.println("st_obj2 = " + st_obj2.tota);
System.out.println("co_obj1 = " + co_obj1.total);
System.out.println("co_obj2 = " + co_obj2.total);
ov_obj.Demo();
ov_obj.Demo(10);
sei_obj.Demo();
System.out.println("sei_obj = " + sei_obj.a);
// System.out.println("sei_obj = " + sei_obj.rate);
}
}
class hensuu{
int total;
void Demo() {
int i;
for (i=1;i < 10; i++)
total+=i;
System.out.println("hen_obj = " + total);
}
}
class stati{
static int tota;
void add(int x) {
tota += x;
}
}
class consto{
int total;
static { // static イニシャライズ
System.out.println("initialize");
}
consto() { // コンストラクタ(クラス名と同名)
total = 0; // 0 クリア
}
consto(int x){
total = x;
}
void add(int x) {
total += x;
}
}
class over{
void Demo() { // メソッド Disp 引数なし
System.out.println("Demo =Nothing");
}
void Demo(int x) { // メソッド Disp 引数 x
System.out.println("Demo ="+ x);
}
}
class seigen{
static int a;
private int rate; // private変数rateの宣言
void Demo() {
a=200;
rate=20;
System.out.println("rate ="+ rate);
}
}
|