クラスの作成

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="";
    }

} }}


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-03-12 (火) 09:13:41