我目前正在學習一個涉及繼承和構造函數的程序。我實際上是C#中的新手,所以我只是想知道爲什麼下面的代碼在第57行有一個錯誤,它表示貸款不包含帶0參數的構造函數。請幫我分析一下它的錯誤。非常感謝你。使用系統的 ;繼承和構造函數的錯誤
class DemoCarLoan3
{
static void Main()
{
Loan aLoan = new Loan(333, "Hanson", 7000.00);
CarLoan aCarLoan = new CarLoan(444, "Carlisle", 30000.00, 2011, "BMW");
Console.WriteLine("Loan #{0} for {1} is for Php{2}",
aLoan.LoanNumber, aLoan.LastName,
aLoan.LoanAmount.ToString("0,000.00"));
Console.WriteLine("Loan #{0} for {1} is for Php{2}",
aCarLoan.LoanNumber, aCarLoan.LastName,
aCarLoan.LoanAmount.ToString("0.00"));
Console.WriteLine(" Loan #{0} is for a {1} {2}",
aCarLoan.LoanNumber, aCarLoan.Year,
aCarLoan.Make);
Console.ReadLine();
}
}
class Loan
{
public const double MINIMUM_LOAN = 5000;
protected double loanAmount;
public int LoanNumber { get; set; }
public string LastName { get; set; }
public double LoanAmount
{
set
{
if (value < MINIMUM_LOAN)
loanAmount = MINIMUM_LOAN;
else
loanAmount = value;
}
get
{
return loanAmount;
}
}
public Loan(int num, string name, double amount)
{
LoanNumber = num;
LastName = name;
LoanAmount = amount;
}
}
class CarLoan : Loan
{
private const int EARLIEST_YEAR = 2006;
private const int LOWEST_INVALID_NUM = 1000;
private int year;
public CarLoan(int num, string name, double amount, int year, string make)
{
Year = year;
Make = make;
}
public int Year
{
set
{
if (value < EARLIEST_YEAR)
{
year = value;
loanAmount = 0;
}
else
year = value;
}
get
{
return year;
}
}
public string Make { get; set; }
public new int LoanNumber
{
get
{
return base.LoanNumber;
}
set
{
if (value < LOWEST_INVALID_NUM)
base.LoanNumber = value;
else
base.LoanNumber = value % LOWEST_INVALID_NUM;
}
}
}
檢查http://stackoverflow.com/questions/7230544/c-sharp-error-parent-does-not-contain-a-constructor-that-takes-0-arguments – argaz