-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
请显示实际的全部要求。你可能会误解他们。 –