代码块练习题:看代码写程序的执行结果。

 1 /*
 2     代码块练习题:
 3         看代码写程序的执行结果。
 4     
 5     输出结果是:
 6         林青霞都60了,我很伤心
 7         我是main方法
 8         Student 静态代码块
 9         Student 构造代码块
10         Student 构造方法
11         Student 构造代码块
12         Student 构造方法
13 */
14 
15 class Student {
16     static {
17         System.out.println("Student 静态代码块");
18     }
19     
20     {
21         System.out.println("Student 构造代码块");
22     }
23     
24     public Student() {
25         System.out.println("Student 构造方法");
26     }
27 }
28 
29 class StudentDemo {
30     static {
31         System.out.println("林青霞都60了,我很伤心");
32     }
33     
34     public static void main(String[] args) {
35         System.out.println("我是main方法");
36         
37         Student s1 = new Student();
38         Student s2 = new Student();
39     }
40 }

我的GitHub地址: https://github.com/heizemingjun
我的博客园地址: http://www.cnblogs.com/chenmingjun
我的蚂蚁笔记博客地址: http://blog.leanote.com/chenmingjun
Copyright ©2018 黑泽明军
【转载文章务必保留出处和署名,谢谢!】
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值