//super Class
public class B
{
protected sum s1 = new sum();
protected sub s2 = new sub();
public B()
{
this.con = con;
this.d = d;
}
public method_demo()
{
// code here
}
}
public class A extends B
{
public method_1(Connection con , Dummy d)
{
super(con,d) ;
}
}
为了测试A类,首先调用超类构造函数。 如何为它编写测试用例。我试图压缩超类中的字段但仍然给出了初始化错误。
答案 0 :(得分:0)
这是我认为你想要的代码:
public class B
{
protected sum s1 = new sum();
protected sub s2 = new sub();
Connection con;
Dummy d;
public B(Connection con, Dummy d)
{
this.con = con;
this.d = d;
}
public method_demo()
{
}
}
public class A extends B
{
//this is a constructor, because is has the same name as the class
public A(Connection con, Dummy d)
{
super(con, d);
}
/* // This is a method, not a constructor:
public method_1(Connection con , Dummy d)
{
super(con,d) ;
}
*/
}