Simple screenshot that explains the non-static invocation.

Here is the code:

 1 /*
 2 Instance invocation in the memory:
 3 
 4 */
 5 package kju.obj;
 6 
 7 import static kju.print.Printer.*;
 8 public class NonStaticInvoke {
 9     public static void main(String[] args) {
10         Person p = new Person("lily");
11         p.setName("lucy");
12     }
13 }
14 
15 class Person {
16     public static final String country = "cn";
17     private String name;
18     public Person(String name) {
19         this.name = name;
20     }
21 
22     public static void showCountry() {
23         println("country = " + country);
24     }
25 
26     public void setName(String name) {
27         this.name = name;
28     }
29 }

The figure below corresponds to the above code:

Simple screenshot that explains the non-static invocation._第1张图片

你可能感兴趣的:(EXPLAIN)