LoginSignup
0
1

More than 5 years have passed since last update.

Javaのstatic

Last updated at Posted at 2017-10-03

javaの変数の前につく「static」ってなに?って思ったので。。。

言葉で説明すると「大元のクラスフィールドに紐付いた変数」。

public class car{
   static int num_car = 0;
   String type;
   String color;

   Car(String type,String color){
      this.type = type;
      this.color = color;
      num_car++;
   }
}

こんな感じのコードがあった場合に"type"と"color"はそのインスタンスフィールド固有のものであるが、"num_car"はインスタンスの数であるため、carクラスフィールド自体に紐づいていてどんどん更新されていくもの。

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1