static关键字
static:静态的 static可以修饰成员变量,称为静态变量,在方法区 标准使用方式:类名.静态变量名 另一种使用方式:对象名.静态变量名 static可以修饰成员方法 ,称为静态方法 标准使用方式:类名.方法名() 另一种使用方式:对象名.方法名() public class Student { String name ; //name与age称为成员变量,在堆 int age ; static String school ; //静态变量,而且在方法区 public void show ( ) { //成员方法 } public static void fun ( ) { //静态方法 } } public class TestStudent { public static void main ( String [ ] args ) { Student . school = "北京大学" ; //静态变量的使用方法,是 类名.静态变量名 //Student.name="张三"; //成员变量 Student stu = new Student ( ) ; stu . name = "张三" ; stu . school = "清华大学" ; //不报错,但是会警告 Student . fun ( ) ; //静态方法, 类名.方法名 //Student.show();/