1 public class Exp10_1 {
2
3 public static void main(String[] args) {
4 //Exp10_1 exp = new Exp10_1();
5 print1();
6 Exp10_1.print2();
7 //print3();
8 /*
9 在类的静态方法里面不能调用类的非静态方法,如果要调用该方法,必须将其定义为静态方法,
10 在类的静态方法里面调用其它静态方法有两种,一是直接写该方法,二是通过类名调用
11 */
12 }
13 public static void print1()
14 {
15 System.out.println("hello!");
16 System.out.println("Java");
17 }
18 public static void print2()
19 {
20 System.out.print("hello");
21 System.out.print("world");
22 }
23 public void print3(){}
24 public void print4()
25 {
26 /*
27 * 在类的非静态方法里面既可以调用类的静态方法,也可以调用类的非静态方法,各有两种
28 * 静态方法:直接调用和使用类名调用
29 * 非静态方法:直接调用和使用this调用
30 * 注意:非静态方法不能通过this调用,静态方法也不能通过类名调用!
31 */
32 print3();
33 this.print4();
34
35 print1();
36 print2();
37 Exp10_1.print1();
38 Exp10_1.print2();
39 }
40 }