我已經編寫了以下Java程序。但是我不斷收到一個錯誤,說我的構造函數的實際和形式參數長度不同。我不明白問題是什麼。有人可以告訴我我的程序有什麼問題,以及我可以如何調試它?Java錯誤 - 實際和正式參數列表的長度不同
class Student
{
String name;
Student(String name)
{
System.out.println("\nThe name of the student is:"+name);
}
}
class Exam extends Student
{
int m1, m2;
Exam(int m1, int m2)
{
System.out.println("\nThe marks obtained in first subject is:"+m1);
System.out.println("\nThe marks obtained in second subject is:"+m2);
}
}
class Result extends Exam
{
int totalmarks;
int compute(int m1, int m2)
{
totalmarks=m1+m2;
return(totalmarks);
}
}
public class StudentTest
{
public static void main(String[] args)
{
Student s = new Student("rose");
Exam e = new Exam(20,20);
Result r = new Result();
System.out.println("\nThe total marks obtained is:"+r.compute(20,20));
}
}
要麼使默認的構造函數只添加超(null);語句作爲考試構造函數中的第一條語句。 – Nimesh 2015-04-03 08:00:44