为什么非要用大写才行??

来源:百度知道 编辑:UC知道 时间:2024/06/03 21:20:35
我在编写一个小程序。
类:
public class MyDate{
private int day = 17;
private int month = 2;
private int year = 2006;
public MyDate(){}
public MyDate(int d,int m,int y){
day = d;
month = m;
year = y;
}
public void setday(int d){
day = d;
}
public int getday(){
return day;
}
public void setmonth(int m){
month = m;
}
public int getmonth(){
return month;
}
public void setyear(int y){
year = y;
}
public int getyear(){
return year;
}
public void display(){
System.out.println(year+"-"+month+"-"+day);
}
}

对象:
public class TestReferenceType {
public static void main(String[] args) {
MyDate d1;
d1 = new MyDate();
d1.setday(8);
d1.setmonth(8);
d1.setyear(2008);
d1.display();
}
}

(我知道上面的代码是错的,但我有个疑问)<

类的名字的第一个字母必须是大写,这是Java的规定,但方法无所谓,全部都是小写也可以。你应该是在类的名字上出了问题。
类的名字都是小写有什么不对?你到底是在写C++还是Java?写C++的话没人管你大小写,写Java的话该大写的时候就必须大写,比如类的第一个字母。这是Java辨认类的方式,小写的统统不被看作是类,即使你前面有加class关键字。

跟其他的东西有关 比如你之前定义的对象 是大写的

你在这里改为小写 当然不可以了