BirthDate.java程序错误在哪里运行不出来写着 c :\myjava>javac Test.java Test.java:46 找不到符号 符号 5
classBirthDate{privateintdate;privateintmonth;privateintyear;publicBirthDate(intd,int...
class BirthDate {
private int date;
private int month;
private int year;
public BirthDate(int d, int m, int y) {
day = d;
month = m;
year = y;
}
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 class Test {
public static void main(String args[]) {
Test test = new Test();
int date = 9;
BirthDate d1 = new BirthDate(7,7,1970);
BirthDate d2 = new BirthDate(1,1,2000);
test.change1(date);
test.change2(d1);
test.change3(d2);
System.out.println("date=" + date);
d1.display();
d2.display();
}
public void change1(int i) {
i = 1234;
}
public void change2(BirthDate b) {
b = new BirthDate(22,2,2004);
}
public void change3(BirthDate b) {
b.setDay(22);
}
}
运行不出来,在c:\myjava\BirthDate\的Test.java目录下
错误结果是:
c:\myjava>javac Test.java
Test.java:46:找不到符号
符号:方法change1(int)
位置:类Test
test.change1(date);
有哪位能帮我看一下哪出错了 展开
private int date;
private int month;
private int year;
public BirthDate(int d, int m, int y) {
day = d;
month = m;
year = y;
}
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 class Test {
public static void main(String args[]) {
Test test = new Test();
int date = 9;
BirthDate d1 = new BirthDate(7,7,1970);
BirthDate d2 = new BirthDate(1,1,2000);
test.change1(date);
test.change2(d1);
test.change3(d2);
System.out.println("date=" + date);
d1.display();
d2.display();
}
public void change1(int i) {
i = 1234;
}
public void change2(BirthDate b) {
b = new BirthDate(22,2,2004);
}
public void change3(BirthDate b) {
b.setDay(22);
}
}
运行不出来,在c:\myjava\BirthDate\的Test.java目录下
错误结果是:
c:\myjava>javac Test.java
Test.java:46:找不到符号
符号:方法change1(int)
位置:类Test
test.change1(date);
有哪位能帮我看一下哪出错了 展开
3个回答
2010-09-15
展开全部
你的change1,2,有问题...你那个 i = 1234 以及 b = new BirthDate(22,2,2004) 都在方法内将变量指向了另外的地址...当参数为形参的时候...传到方法内的变量为副本...在方法内修改的也是副本的值...
修改如下...
public class Test {
public int change1() {
return 1234;
}
public BirthDate change2() {
BirthDate b = new BirthDate(22,2,2004);
return b;
}
public static void main(String args[]) {
Test test = new Test();
int date = 9; // a
BirthDate d1 = new BirthDate(7,7,1970); // b
BirthDate d2 = new BirthDate(1,1,2000);
test.change1(date); //将 a 处与此处合并为 int date = test.change1();
test.change2(d1); //将 b 处与此处合并为 BirthDate d1 = test.change2();
test.change3(d2);
System.out.println("date=" + date);
d1.display();
d2.display();
}
修改如下...
public class Test {
public int change1() {
return 1234;
}
public BirthDate change2() {
BirthDate b = new BirthDate(22,2,2004);
return b;
}
public static void main(String args[]) {
Test test = new Test();
int date = 9; // a
BirthDate d1 = new BirthDate(7,7,1970); // b
BirthDate d2 = new BirthDate(1,1,2000);
test.change1(date); //将 a 处与此处合并为 int date = test.change1();
test.change2(d1); //将 b 处与此处合并为 BirthDate d1 = test.change2();
test.change3(d2);
System.out.println("date=" + date);
d1.display();
d2.display();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你在class BirthDate 根本没定义day
private int date;
public BirthDate(int d, int m, int y) {
day = d;
month = m;
year = y;
}
除了这里有问题 其他没问题
private int date;
public BirthDate(int d, int m, int y) {
day = d;
month = m;
year = y;
}
除了这里有问题 其他没问题
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private int date; 改成private int day;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询