Java继承结构中类的初始化

    初学者测试

    昨天自考考了《java程序语言设计》,有点不太记得类的初始化过程了,顺便复习了一下。

    同样准备了测试题一枚。把自己的email分散到输出中,如果正确输出,说明分析正确了。

    不行怎么行,这是基础。下面程序请先分析,如果结果(用白色字体是输出结果)正确,说明您对java类的初始化已经很熟悉,算是过关,如果没有,那赶紧复习吧。

 

package nie.test.extend;  

/** 子构造子的初始化过程: 
 * @author dotjar 
 *  1.父static域 
 *  2.父static块 
 *  3.子static域 
 *  4.子static块 
 *  5.父普通域
 *  6.父普通块{} 
 *  7.父构造子 
 *  8.子普通域
 *  9.子普通块{} 
 *  10.子构造子 
 */  
public class Test {  
    public static void main(String[] args) {  
        new Son("s");  
    }  
}  

class Father {  
    static protected String s = "father_static_property_string";  //1
    protected String b = "father_normal_property_string";  //5
    static {  
        s = "o";  //2
        System.out.print("d");  
        System.out.print(s);  
    }  
    {  
        b="r";  //6
        System.out.print("a");  
        System.out.print(b);  
    }  

    Father() {  
        this("@");  
        System.out.print("1");  //8
    }  

    Father(String s) {  
        System.out.print(s);  //7
    }  
}  

class Son extends Father {  
	public static String s = "son_static_property_string"; //3
	public String b = "son_normal_property_string"; //9
    static {  
        s = "j";  //4
        System.out.print("t");  
        System.out.print(s);  
    }  
    {  
        b = "3";  //10
        System.out.print("6");  
        System.out.print(b);  
    }  

    Son() {  
        System.out.print(".");  //11
    }  

    Son(String s) {  
        this();  
        System.out.print("com");  //12
    }  
}  
 

 测试完自己的输出,可以用鼠标选中下一行,检查。

这里:dotjar@163.com

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值