基本上,我在一本書中做了一個Java練習,這個源代碼就是它對練習的回答。然而,eclipse說在底部的第三行有一個錯誤,說「構造函數PhoneNumber()是未定義的」。但據我瞭解,這個特定的構造函數是正確定義的,所以問題是什麼?Java構造函數undefined
public class PhoneNumber {
// Only the relevant source codes are posted here.
// I removed other bits cause I'm sure they are not responsible for the
// error
private char[] country;
private char[] area;
private char[] subscriber;
public PhoneNumber(final String country, final String area, final String subscriber) {
this.country = new char[country.length()];
country.getChars(0, country.length(), this.country, 0);
this.area = new char[area.length()];
area.getChars(0, area.length(), this.area, 0);
this.subscriber = new char[subscriber.length()];
subscriber.getChars(0, subscriber.length(), this.subscriber, 0);
checkCorrectness();
}
private void runTest() {
// method body
}
public static void main(final String[] args) {
(new PhoneNumber()).runTest(); // error here saying :
// "The constructor PhoneNumber() is undefined"
}
}
感謝您的解釋和解決方案。非常感謝。 – Kyle