>>>>>在实例化MoneyTest生成test对象的时候使用
TestCase test= new MoneyTest("simple add")
不就可以了吗?为什么还需要2、3、4、5、6行所示的代码?
这样做可以吗?谁能告诉我一下原理,谢谢。
确实可以这样:TestCase test = new MoneyTest("simple add");
这里这样做是即时创建了一个类,这个类也可以这样来实现:
class SomeClass extends MonenyTest{//extends(if MoneyTest is a class) or implements(if MoneyTest is an interface)
//实现这个类
public void runTest() {
testAdd(); }这种用法在Swing中经常可以见到: SomeComponent.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//do sth
}
});这里的new ActionListener(){...}就是这种使用方式。
TestCase test= new MoneyTest("simple add")
不就可以了吗?为什么还需要2、3、4、5、6行所示的代码?
这样做可以吗?谁能告诉我一下原理,谢谢。
确实可以这样:TestCase test = new MoneyTest("simple add");
这里这样做是即时创建了一个类,这个类也可以这样来实现:
class SomeClass extends MonenyTest{//extends(if MoneyTest is a class) or implements(if MoneyTest is an interface)
//实现这个类
public void runTest() {
testAdd(); }这种用法在Swing中经常可以见到: SomeComponent.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//do sth
}
});这里的new ActionListener(){...}就是这种使用方式。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货