public class HelloWorld { // 定义静态变量,保存班级名称 String className = "JAVA开发一班"; public static void main(String[] args) { //通过类名来访问 System.out.print(HelloWorld.className); //定义对象 HelloWorld test=new HelloWorld(); // 访问静态变量,输出班级名称 //通过对象名访问对象 System.out.println( test.className); test.className="我爱limengyi"; // 访问静态变量,输出改变后的值; System.out.println( test.className); } }