
java中子类如何继承有参数的父类方法
classfathertest{publicfathertest(inti){System.out.println("hello"+"i");}}publicclasst...
class fathertest{
public fathertest(int i){
System.out.println("hello"+"i");
}
}
public class test extends fathertest {
super test(int i){
//错误:Implicit super constructor fathertest() is undefined. Must explicitly invoke another
// constructor
System.out.println("java");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
test s=new test(0);
}
}
不是说只要在子类方法构造中用super加参数就可以了吗?请问该如何修改? 展开
public fathertest(int i){
System.out.println("hello"+"i");
}
}
public class test extends fathertest {
super test(int i){
//错误:Implicit super constructor fathertest() is undefined. Must explicitly invoke another
// constructor
System.out.println("java");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
test s=new test(0);
}
}
不是说只要在子类方法构造中用super加参数就可以了吗?请问该如何修改? 展开
2016-09-25
展开全部
class fathertest{
public fathertest(int i){
System.out.println("hello"+"i");
}
}
public class test extends fathertest {
test(int i){
super(i);
System.out.println("java");
}
public static void main(String[] args) {
test s=new test(0);
}
}
public fathertest(int i){
System.out.println("hello"+"i");
}
}
public class test extends fathertest {
test(int i){
super(i);
System.out.println("java");
}
public static void main(String[] args) {
test s=new test(0);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询