Javaのstatic修飾語
1388 ワード
1.static修飾のメンバー変数とメソッド、従属クラス.
2.一般変数とメソッドは、オブジェクトに属します.
public class User2 {
int id; // ID
String name; //
String grade; //
# static
static String slogan = "study hard and make progress every day";
public User2(int id,String name) {
this.id = id;
this.name = name;
}
public void say() {
System.out.println("student"+name+"say");
System.out.println(slogan); #
}
#
public static void speakSlogan() {
System.out.println(slogan);
}
public static void main(String []args) {
User2 student = new User2(666," "); # student
User2.speakSlogan(); #
User2.slogan = "Self-discipline is my freedom"; #
User2.speakSlogan(); #
}
}