//: c07:Frog.java
// Cleanup and inheritance.
import com.bruceeckel.simpletest.*;
class Characteristic {
private String s;
Characteristic(String s) {
this.s = s;
System.out.println("Creating Characteristic " + s);
}
protected void dispose() {
System.out.println("finalizing Characteristic " + s);
}
}
class Description {
private String s;
Description(String s) {
this.s = s;
System.out.println("Creating Description " + s);
}
protected void dispose() {
System.out.println("finalizing Description " + s);
}
}
class LivingCreature {
private Characteristic p = new Characteristic("is alive");
private Description t = new Description("Basic Living Creature");
LivingCreature() {
System.out.println("LivingCreature()");
}
protected void dispose() {
System.out.println("LivingCreature dispose");
t.dispose();
p.dispose();
}
}
class Animal extends LivingCreature {
private Characteristic p = new Characteristic("has heart");
private Description t = new Description("Animal not Vegetable");
Animal() {
System.out.println("Animal()");
}
protected void dispose() {
System.out.println("Animal dispose");
t.dispose();
p.dispose();
super.dispose();
}
}
class Amphibian extends Animal {
private Characteristic p = new Characteristic("can live in water");
private Description t = new Description("Both water and land");
Amphibian() {
System.out.println("Amphibian()");
}
protected void dispose() {
System.out.println("Amphibian dispose");
t.dispose();
p.dispose();
super.dispose();
}
}
public class Frog extends Amphibian {
private static Test monitor = new Test();
private Characteristic p = new Characteristic("Croaks");
private Description t = new Description("Eats Bugs");
public Frog() {
System.out.println("Frog()");
}
protected void dispose() {
System.out.println("Frog dispose");
t.dispose();
p.dispose();
super.dispose();
}
public static void main(String[] args) {
Frog frog = new Frog();
System.out.println("Bye!");
frog.dispose();
monitor.expect(new String[] {
"Creating Characteristic is alive",
"Creating Description Basic Living Creature",
"LivingCreature()",
"Creating Characteristic has heart",
"Creating Description Animal not Vegetable",
"Animal()",
"Creating Characteristic can live in water",
"Creating Description Both water and land",
"Amphibian()",
"Creating Characteristic Croaks",
"Creating Description Eats Bugs",
"Frog()",
"Bye!",
"Frog dispose",
"finalizing Description Eats Bugs",
"finalizing Characteristic Croaks",
"Amphibian dispose",
"finalizing Description Both water and land",
"finalizing Characteristic can live in water",
"Animal dispose",
"finalizing Description Animal not Vegetable",
"finalizing Characteristic has heart",
"LivingCreature dispose",
"finalizing Description Basic Living Creature",
"finalizing Characteristic is alive" });
}
} // /:~
分享到:
相关推荐
类多重继承的模糊性的消除,类多重继承的模糊性的消除
如何在Java中消除实现继承和面向接口编程
该资源为自定义控件系列文章第三弹 继承控件 带清除按钮EditText的源码
类多重继承的模糊性的消除2,类多重继承的模糊性的消除2
全书共分十八章,内容涉及对象的演化、数据抽象、隐藏实现、初始化与清除、函数重载与缺省参数、输入输出流介绍、常量、内联函数、命名控制、引用和拷贝构造函数、运算符重载、动态对象创建、继承和组合、多态和虚...
全书共分十八章,内容涉及对象的演化、数据抽象、隐藏实现、初始化与清除、函数重载与缺省参数、输入输出流介绍、常量、内联函数、命名控制、引用和拷贝构造函数、运算符重载、动态对象创建、继承和组合、多态和虚...
第4章 初始化与清除 4.1用构造函数确保初始化 4.2用析构函数确保清除 4.3清除定义块 4.3.1for循环 4.3.2空间分配 4.4含有构造函数和析构函数的stash 4.5含有构造函数和析构函数的stack 4.6集合初始化 4.7缺省构造...
全书共分十八章,内容涉及对象的演化、数据抽象、隐藏实现、初始化与清除、函数重载与缺省参数、输入输出流介绍、常量、内联函数、命名控制、引用和拷贝构造函数、运算符重载、动态对象创建、继承和组合、多态和虚...
基类 继承过程将创建一个新的派生类,它由基类的成员加上派生类添加的任何新成员组成。在多重继承中,可以构建一个继承关系图,...若要消除此冗余,可以在继承此类类时将其声明为虚拟基类。 多个基类 如多重继承中所
目前游戏引擎的事件驱动因采用仿MFC的架构,导致程序多重继承时会发生4407警告,这两天修复该bug之后,在做游戏细节讲解说明。 目前按钮控件事件响应和MFC下的按钮响应一模一样,游戏代码中主窗口下按钮采用MFC消息...
并删除性能函数和权重函数,设阅读器的邻居数与覆盖数的比值作为冗余阅读器判定值。最后,通过实例分析证明改进算法的有效性,并和算法RRE、LEO、ERRE进行仿真对比分析。实验结果表明,改进算法在继承ERRE算法优点的...
第4章初始化与清除 第5章函数重载与缺省参数 第6章输入输出流介绍 第7章常量 第8章内联函数 第9章命名控制 第10章引用和拷贝构造函数 第11章运算符重载 第12章动态对象创建 第13章继承和组合 第14章多态和虚函数 第...
全书共分十八章,内容涉及对象的演化、数据抽象、隐藏实现、初始化与清除、函数重载与缺省参数、输入输出流介绍、常量、内联函数、命名控制、引用和拷贝构造函数、运算符重载、动态对象创建、继承和组合、多态和虚...
可以滚动图片,消除背景,设置文字大笑,颜色,接口做的还是不 错的
MyView2自定义view之组合View控件和继承View控件自定义Drawable:步骤:1.传进一张bitmap图片2.将bitmap传进BitmapShader3.将BitmapShader传进paint画笔(还要消除锯齿)4.绘制drawable的width,height(即...
从父元素继承float属性的值 没有浮动之前,所有的元素在文档的普通流中(如下图:) 某元素浮动之后,它便飘了起来,我们称之为脱离文档流。(就好比气球充满气体之后便离开地面飞了~~) 他们都是...
全书共分十八章,内容涉及对象的演化、数据抽象、隐藏实现、初始化与清除、函数重载与缺省参数、输入输出流介绍、常量、内联函数、命名控制、引用和拷贝构造函数、运算符重载、动态对象创建、继承和组合、多态和虚...
全书共分十八章,内容涉及对象的演化、数据抽象、隐藏实现、初始化与清除、函数重载与缺省参数、输入输出流介绍、常量、内联函数、命名控制、引用和拷贝构造函数、运算符重载、动态对象创建、继承和组合、多态和虚...
这样,通过把基类继承声明为虚拟的,就只能继承基类的一份拷贝,从而消除歧义。用virtual限定符把基类继承说明为虚拟的。 (1) 一个类可以在一个类族中既被用作虚基类,也被用作非虚基类。 (2) 在派生类的对象中,...
全书共分十八章,内容涉及对象的演化、数据抽象、隐藏实现、初始化与清除、函数重载与缺省参数、输入输出流介绍、常量、内联函数、命名控制、引用和拷贝构造函数、运算符重载、动态对象创建、继承和组合、多态和虚...