java编程思想中的例题,有些不懂

shirui8653719 2013-07-13 08:20:11
import com.bruceeckel.simpletest.*;

class Art {
Art() {
System.out.println("Art constructor");
}
}

class Drawing extends Art {
Drawing() {
System.out.println("Drawing constructor");
}
}

public class Cartoon extends Drawing {
private static Test monitor = new Test();
public Cartoon() {
System.out.println("Cartoon constructor");
}
public static void main(String[] args) {
Cartoon x = new Cartoon();
monitor.expect(new String[] {
"Art constructor"
"Drawing constructor"
"Cartoon constructor"
});
}
}




上面的private static Test monitor = new Test();还有
monitor.expect(new String[] {
"Art constructor"
"Drawing constructor"
"Cartoon constructor"
});
是什么意思?没看懂啊,我在java编程思想第三版p146中看到的,有谁懂吗?
...全文
249 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
桃之_夭夭 2013-07-14
  • 打赏
  • 举报
回复
目测楼猪是刚学java的 百度文库搜一个"Java基础教程.pdf"这本基础部分讲得非常细,每段代码都有说明
齐岳 2013-07-14
  • 打赏
  • 举报
回复
将整个new String[]{...}作为一个参数传入到monitor对象的expect方法中。 这个expect是作者自己写的一个方法,不是java自带的。 在think in java中第一次出现monitor.expect方法时作者有提到的。
地下室森林 2013-07-13
  • 打赏
  • 举报
回复
private static Test monitor = new Test();是测试类,你在那边看下那个累里面的内容。expect()应该是Test的一个方法
starnight_cyber 2013-07-13
  • 打赏
  • 举报
回复
估计你没看这个包里的东西:import com.bruceeckel.simpletest.*;里面的Test类 private static Test monitor = new Test(); //Test类对象作为Cartoon类的属性 //Test类中的expect()方法需要传递一个字符串数组 monitor.expect(new String[] { //新建字符串数组,数组内容如下 "Art constructor" "Drawing constructor" "Cartoon constructor" });
rencht 2013-07-13
  • 打赏
  • 举报
回复
预期的输出结果呗, monitor测试类估计在前面的章节就用到过吧,仔细看看咯

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧