class Student {
//1.数据成员
private String name;
private String sex;
public static String school = "岳麓书院"; //公布静态数据成员
// 2.省略构造方法;
//3.省略setter和getter方法;
//4.功能方法
public void display(){
String info = "姓名:"+this.name+",年龄:"+this.sex;
info=info+",学校:"+Student.school;
System.out.println(info);
}
}
public class Demo{
public static void main(String[]args){
Student swk = new Student("孙悟空","男");
Student zbj = new Student("猪八戒","男");
Student.school="岳麓书院";
swk.display();
zbj.display();
System.out.println("====输出修改校名之后的对象信息====");
Student.school="岳麓学院";
//swk.school="岳麓学院";
swk.display();
zbj.display();
}
}
标签:静态数据,school,应用,成员,swk,public,Student,display,String
From: https://blog.csdn.net/2401_83191214/article/details/137028151