Public class Person {// Name String name; // Age (private) private int age; {} public Person() {system.out.println (" no argument constructor "); } public Person(String name) {this.name = name; System.out.println(" argument constructor "); } public void setName(String name) {this.name = name; } public String getName() {return name; Public void run() {system.out.println (name + "run "); } public static void eat() {system.out.println (name + "eat "); System. The out. Println (" eat "); }}Copy the code
Public class test {public static void main(String[] args) {public static void main(String[] args) {Person p = new Person(); Person p = new Person(" DZM "); Person p = new Person(" DZM "); // set name // p.name = "DZM "; p.setName("dzm"); // Call the object method p.run(); // Call the class method person.eat (); }}Copy the code