一个java错误
public class Text {
class BirthDate{
private int day;
private int month;
private int year;
public BirthDate(int d,int m,int y){
d=day;
m=month;
y=year;
}
public void setDay(int d)
{
day=d;
}
public void setMonth(int m)
{
month=m;
}
public void setYear(int y)
{
year=y;
}
public int getDay()
{
return day;
}
public int getMonth()
{
return month;
}
public int getYear()
{
return year;
}
public void display(){
System.out.println(day+"-"+month+"-"+year);
}
}
public static void main(String[] args) {
Text text=new Text();
int day=9;
BirthDate d1=new BirthDate(1,5,2001);
BirthDate d2=new BirthDate(5,7,1997);
text.change1(day);
text.change2(d1);
text.change3(d2);
System.out.println("day="+day);
d1.display();
d2.display();
}
public void change1(int i)
{
i=123;
}
public void change2(BirthDate b)
{
b=new BirthDate(3,8,2008);
}
public void change3(BirthDate b)
{
b.setDay(23);
}
}
为什么BirthDate d1=new BirthDate(1,5,2001);
BirthDate d2=new BirthDate(5,7,1997);不能初始化,编译会出错?
------解决方案--------------------BirthDate d1=text.new BirthDate(1,5,2001)