java抽象方法声明_java – 无法声明一个抽象方法private

我想这样做,但我不能.这是我的场景和理性.我有一个抽象类的测试用例,其抽象方法叫做test(). test()方法由子类定义;它将通过某种应用程序的逻辑来实现,例如CRMAppTestCase扩展了CompanyTestCase.我不想直接调用test()方法,我希望超类调用test()方法,而子类可以调用一个调用这个方法的方法(并且还做其他工作,比如设置当前的例如,在执行测试之前的日期时间).示例代码:

public abstract class CompanyTestCase {

//I wish this would compile, but it cannot be declared private

private abstract void test();

public TestCaseResult performTest() {

//do some work which must be done and should be invoked whenever

//this method is called (it would be improper to expect the caller

// to perform initialization)

TestCaseResult result = new TestCaseResult();

result.setBeginTime(new Date());

long time = System.currentTimeMillis();

test(); //invoke test logic

result.setDuration(System.currentTimeMillis() - time);

return result;

}

}

然后延长这个….

public class CRMAppTestCase extends CompanyTestCase {

public void test() {

//test logic here

}

}

然后叫它….

TestCaseResult result = new CRMAppTestCase().performTest();

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值