package c06.answer;
// (1)注意:初始化的时候,先是父类的static成员,子类的static成员;然后是父类的
//一般成员和构造方法,再轮到子类的成员和构造方法。下面的实例中没有static变量
//那么就按照先变量后构造方法的顺序,先父类后子类的顺序。
//(2)注意:类的清理动作的顺序和生成顺序恰恰相反,所以先子类清理再到父类清理。
class Component1
{
Component1(int i)
{
System.out.println("Compoment1's construstor");
}
void dispose()
{
System.out.println("Component1 dispose");
}
}
class Component2
{
Component2(int i)
{
System.out.println("Compoment2's construstor");
}
void dispose()
{
System.out.println("Component2 dispose");
}
}
class Component3
{
Component3(int i)
{
System.out.println("Compoment3's construstor");
}
void dispose()
{
System.out.println("Component3 dispose");
}
}
class Root
{
Component1 component1= new Component1(4);
Component2 component2= new Component2(5);
Component3 component3= new Component3(6);
public Root(int i)
{
System.out.println("Root's construstor");
}
void dispose()
{
System.out.println("Root dispose");
component3.dispose();
component2.dispose();
component1.dispose();
}
}
class Stem extends Root
{
Component1 component1= new Component1(7);
Component2 component2= new Component2(8);
Component3 component3= new Component3(9);
public Stem(int i)
{
super(888);
System.out.println("Stem's construstor"+"\n");
}
public void dispose()
{
System.out.println("Stem dispose");
component3.dispose();
component2.dispose();
component1.dispose();
super.dispose();
}
}
public class E10_ConstructorOrder {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Stem stem = new Stem(999);
try
{
}finally{
stem.dispose();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
thinking in java (第三版)答案(4,5,6).rar (43个子文件)
第四章
4.7.14.txt 618B
4.7.4.txt 491B
4.7.2.txt 425B
4.7.15.txt 520B
4.7.10.txt 664B
4.7.6(1).txt 510B
4.7.17.txt 518B
4.7.3.txt 172B
4.7.6(2).txt 873B
4.7.18.txt 661B
4.7.8.txt 391B
4.7.16.txt 669B
4.7.5.txt 557B
4.7.1.txt 214B
4.7.9.txt 724B
第五章
5.7.txt 921B
5.8.txt 273B
5.3.txt 335B
5.6.txt 496B
5.2.txt 221B
第六章
6.8.txt 617B
6.18.txt 986B
6.6.txt 752B
6.11.txt 1KB
6.14.txt 982B
6.1.txt 562B
6.20.txt 295B
6.4.txt 1KB
6.9.txt 2KB
6.13.txt 1KB
6.16.txt 626B
6.22.txt 633B
6.7.txt 262B
6.5.txt 700B
6.21.txt 363B
6.10.txt 1KB
6.23.txt 1KB
6.19.txt 671B
6.17.txt 823B
6.3.txt 1KB
6.12.txt 2KB
6.2.txt 1KB
6.15.txt 773B
共 43 条
- 1
资源评论
andevele
- 粉丝: 84
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功