enter image description here 我有三个课程c6,c7和c8,如下所示:
public class c6{
private String name;
private int age;
public c6() {
//default constructor
}
public c6(String name,int age){
this.name = name;
this.age = age;
}
public void show(){
System.out.println("Name :"+name);
System.out.println("Age :"+age);
}}
这是我的班级c7
public class c7 extends c6{
private double salary;
public c7() {
//default constructor
}
public c7(String name,int age,double salary) {
super(name,age);
this.salary = salary;
}
public void show(){
super.show();
System.out.println("Salary :"+salary);
}}
这是我的班级c8:
public class c8 {
public static void main(String[] args) {
c7 ob1 = new c7("akhil",12,9000.00);
c7 ob2 = new c7("akhil",12);
ob1.show();
ob2.show();
}}
我试图将c6的内容继承到c7中 我得到的错误是
c8.java:4: error: constructor c7 in class c7 cannot be applied to given types;
c7 ob1 = new c7("akhil",12,9000.00);
^
required: no arguments
found: String,int,double
原因:实际和正式的参数列表长度不同
我为c8.java:5