main()のクラスを作るのとは別にサブルーチンの集まりや、変数を定義するクラスを作る場合・・・
#codeprettify{{ class クラス名{
要素1
要素2
・
・
・
・
} }}
例
#codeprettify{{ class Test{
int test; String str;
} }}
また、コンストラクタを作成する場合は
#codeprettify{{ class クラス名{
要素1
要素2
・
・
クラス名(コンストラクタ)
・
} }}
という流れになる
例
#codeprettify{{ class Test{
int test;
String str;
Test(int atest,String str){
test=atest;
str=astr;
}
}
}}
オーバーロードするコンストラクタを作成する場合は
引数が異なるコンストラクタを定義しなければならない
例
#codeprettify{{ class Test{
int test; String str;
Test(int atest,String astr){
test=atest;
str=astr;
}
Test(int atest){
test=atest;
str="";
}
} }}