我编写了Accessors和Mutators方法,但我仍然无法访问私有变量!为什么?

Abd*_*ahR 1 java methods class accessor mutators

我用自己的私有变量编写了我的类,然后我编写了访问这些变量所需的访问器和mutator方法,但是在编写主类后运行它时这不起作用.为什么会这样?请查看我的代码:

public class DateTest{
    public static void main (String [] args){

        Date d1 = new Date();
        Date d2 = new Date();

        d1.month = "February ";
        d1.day = 13;
        d1.year = 1991;

        d2.month = "July";
        d2.day = 26;
        d2.year = 1990;

        d1.WriteOutput();
        d2.WriteOutput();
        }
    }


      class Date {

private String month;
private int day;
private int year;

public String getMonth(){
    return month;
                     }
public int getDay(){
    return day;
                   }
public int getYear(){

    return year;    }

public void setMonth(String m){
    if (month.length()>0)
        month = m;
                      }
public void setDay(int d){
    if (day>0)
     day = d;       }
public void setYear(int y){
     if (year>0)
     year = y;
                          }

   public void WriteOutput(){
    System.out.println("Month " + month + "Day "+ day + " year" + year);
    }
    }
Run Code Online (Sandbox Code Playgroud)

请大家耐心等待我,我真的是一个"新手"程序员

JB *_*zet 6

应该调用访问器方法.而已.

d1.setMonth("February");
d1.setDay(13);
Run Code Online (Sandbox Code Playgroud)