五 面向对象
5.9 static 关键字
public class Student { private static int age; //静态变量 private double score; // 非静态变量 public void run(){ } public static void go(){ } public static void main(String[] args) { Student s1 = new Student(); //s1是对象 System.out.println(Student.age); //通过Student类调用age // System.out.println(Student.score); //不能通过Student类调用 非静态变量 System.out.println(s1.age); //通过对象调用age System.out.println(s1.score); //通过对象调用score Student.go(); go(); //静态的可以直接调用 new Student().run(); // } }