1.Class Student
package demo_static; public class Student { private String name; private int age; private String sex; private int stuNumber; private static String classroomNumber; public Student() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public int getStuNumber() { return stuNumber; } public void setStuNumber(int stuNumber) { this.stuNumber = stuNumber; } public static String getClassroomNumber() { return classroomNumber; } public static void setClassroomNumber(String classroomNumber) { Student.classroomNumber = classroomNumber; } public void Learning(){ System.out.println("Learning is the duty !"); } public static void Examing(){ System.out.println("please join the exam!"); } }
2.demo_student
package demo_static; public class demo_student { public static void main(String[] args){ Student one=new Student(); one.setAge(18); one.setName("Alex"); one.setSex("male"); one.setStuNumber(49); Student.setClassroomNumber("1303"); one.Learning(); System.out.println("age: "+one.getAge()+" name: "+one.getName()+" sex: " +one.getSex()+" stuNumber: "+one.getStuNumber()+"ClassroomNumber: "+Student.getClassroomNumber()); Student.Examing(); } }
ret:
Learning is the duty !
age: 18 name: Alex sex: male stuNumber: 49ClassroomNumber: 1303
please join the exam!