「メンバ変数を使ってみる」の編集履歴(バックアップ)一覧はこちら
「メンバ変数を使ってみる」(2006/02/14 (火) 14:03:15) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
*メンバ変数を使ってみる
クラスに登録されているメソッドや変数のことをメンバと呼びます
んで、変数のことをメンバ変数と呼んだりするようです
メンバ変数を使用するには
-クラスの宣言をするときに変数をクラス内で宣言
-オブジェクトを作成
-ばしばし使う
という流れになります
まずはクラスの宣言
//りんごクラス
class Apple {
int size; //大きさ
int cnt; //数
}
オブジェクトを作成
Apple apple0 = new Apple();
メンバ変数にアクセスするには
作成した「オブジェクトの名前.変数名」でアクセスできます
apple0.cnt = 10;
んで以下サンプル全文
//りんごクラス
class Apple {
int size; //大きさ
int cnt; //数
}
class Sample {
public static void main(String args[]) {
Apple apple0 = new Apple();
apple0.cnt = 10;
apple0.size = 50;
System.out.println(apple0.size + "サイズのりんご" + apple0.cnt + "個");
}
}
****■[[戻る>クラス]]
*メンバ変数を使ってみる
クラスに登録されているメソッドや変数のことをメンバと呼びます
んで、変数のことをメンバ変数と呼んだりするようです
メンバ変数を使用するには
-クラスの宣言をするときに変数をクラス内で宣言
-オブジェクトを作成
-ばしばし使う
という流れになります
まずはクラスの宣言
//りんごクラス
class Apple {
int size; //大きさ
int cnt; //数
}
オブジェクトを作成
Apple apple0 = new Apple();
メンバ変数にアクセスするには
作成した「オブジェクトの名前.変数名」でアクセスできます
apple0.cnt = 10;
*****サンプル
//りんごクラス
class Apple {
int size; //大きさ
int cnt; //数
}
class Sample {
public static void main(String args[]) {
Apple apple0 = new Apple();
apple0.cnt = 10;
apple0.size = 50;
System.out.println(apple0.size + "サイズのりんご" + apple0.cnt + "個");
}
}
****■[[戻る>クラス]]
表示オプション
横に並べて表示:
変化行の前後のみ表示: