public class Student {
/*
* 1.被static修饰的成员,会被该类的所有对象共享
* 2.被static修饰的成员,会随着类的加载而加载,优先于对象存在
* 3.可以通过类名调用
* */
String name;
int age;
static String school;
public void show()
{
System.out.println(name+"..."+age+"..."+school);
}
static public void print(){
System.out.println(school);
}
}
public class TestStatiuc {
public static void main(String[] args) {
Student stu = new Student();
stu.name = "lili";
stu.age = 13;
stu.school = "北大";
stu.show();
Student stu1 = new Student();
stu1.school = "清华";
stu1.show();
stu.show();
System.out.println(Student.school);
stu.print();
}
}
static关键字
最新推荐文章于 2024-09-09 15:42:52 发布