[Static static keyword to modify member variables]

package cn.itcast.day08.demo03;

/*
If a member variable uses the static keyword, then the variable no longer belongs to the object itself, but to the class it is in. Multiple objects share the same data.
 */
public class Demo01StaticField {
    public static void main(String[] args) {
        Student one = new Student("Guo Jing",19);
        one.room = "Classroom 101";
        System.out.println("Name: "+one.getName()+", age: "+one.getAge()+", classroom: "+one.room+", student number: "+one.getId() );

        Student two = new Student("Huang Rong",16);
        System.out.println("Name: "+two.getName()+", age: "+two.getAge()+", classroom: "+two.room+", student ID: "+two.getId() );
    }
}

Guess you like

Origin blog.csdn.net/m0_48114733/article/details/123324888