一个java错误

xfsunxiaolong 2011-10-08 02:17:49
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);不能初始化,编译会出错?
...全文
41 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
soli11722984 2011-10-08
  • 打赏
  • 举报
回复
BirthDate d1=text.new BirthDate(1,5,2001)

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧