-1
我試圖創建一個使用在我的主要的人的構造人與代碼如何通過外部類構造函數訪問內部類?
Person outerClass = new Person("Anon", new Date(06,03,1991), null);
,但它說,它無法找到該類日期。我是否正確地填寫這個構造函數並調用了類間?
public class Person implements Cloneable
{
private String name;
private Date born;
private Date died;//null indicates still alive.
public Person(String initialName, Date birthDate, Date deathDate)
{
if (consistent(birthDate, deathDate))
{
name = initialName;
born = new Date(birthDate);
if (deathDate == null)
died = null;
else
died = new Date(deathDate);
}
else
{
System.out.println("Inconsistent dates. Aborting.");
System.exit(0);
}
}
private class Date
{
private String month;
private int day;
private int year; //a four digit number.
public Date()
{
month = "January";
day = 1;
year = 1000;
}
public Date(int monthInt, int day, int year)
{
setDate(monthInt, day, year);
}
爲什麼在所有的事情聖潔的名稱,你會讓日期私人內部類?爲什麼不簡單地使它成爲一個獨立的公共類(儘管改變它的名字以避免與java.util.Date混淆)? –
多數民衆贊成我也在想,但任務要求它:/ – rreg101
請顯示實際的全部要求。你可能會誤解他們。 –