类的静态方法小结

 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 }

 

转载于:https://www.cnblogs.com/Jason404/p/6707796.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值