- 最終更新
- 2026/08/17
3秒でわかる
クラスの中に宣言して、オブジェクトごとの状態を保持し続ける変数のこと。メソッドはこの値を読み書きしながら処理を進めます。
30秒図解
もう少し詳しく
どういうものか
フィールドは、
なぜ必要か
同じ
具体例
public class BankAccount {
private String owner; // フィールド
private int balance; // フィールド
public BankAccount(String owner, int balance) {
this.owner = owner;
this.balance = balance;
}
public void withdraw(int amount) {
int fee = 100; // ローカル変数
this.balance -= amount + fee;
}
}fee はbalance は
つまずきやすいところ
引数とthis をstatic をstatic で
似た用語との違い
| 用語 | 生存期間 | どこに属するか |
|---|---|---|
| フィールド | オブジェクトが | インスタンス |
| ローカル変数 | メソッドの | メソッド |
| static フィールド | プログラムの | クラス |
覚え方
フィールドは

