Simple screenshot that explains the non-static invocation.

时间:2021-07-27 08:07:57

Here is the code:

 /*
Instance invocation in the memory: */
package kju.obj; import static kju.print.Printer.*;
public class NonStaticInvoke {
public static void main(String[] args) {
Person p = new Person("lily");
p.setName("lucy");
}
} class Person {
public static final String country = "cn";
private String name;
public Person(String name) {
this.name = name;
} public static void showCountry() {
println("country = " + country);
} public void setName(String name) {
this.name = name;
}
}

The figure below corresponds to the above code:

Simple screenshot that explains the non-static invocation.