class student{   private String id;     private String name;    private int MyDate;   private int age;           public String getId()   {return  id;  }   public String getName()   { return name;  }   public String getMyDate()   { return MyDate;  }   public int getAge()   { return age;  }   void setAge(int age)   { this.age = age;  }   void setAge(int MyDate)   { this.MyDate = MyDate;  }
   } 
   public class TestStudent   { public static void main(String args[])   { student stu = new student("0401398", "廖小明", "2008 9 1",20);    System.out.println("student info: " + "\n学号:"+stu.getId()+ "\n姓名"+   stu.getName()+"\n性别:"+stu.getMyDate()+ "\n年龄:"+stu.getAge());     stu.setAge(19);stu.setMyDate(2008 9 1);
    System.out.println("修改后的年龄为:"+stu.getAge());   }   } 
MyDate是入学日期

解决方案 »

  1.   

    class Student {//类名要大写 private String id; private String name; private int MyDate; private int age;

    public Student(String id, String name, int MyDate, int age) {
    this.id = id;
    this.name = name;
    this.MyDate = MyDate;
    this.age = age;
    } public String getId() {
    return id;
    } public String getName() {
    return name;
    } public int getMyDate()//返回类型要一致 {
    return MyDate;
    } public int getAge() {
    return age;
    } void setAge(int age) {
    this.age = age;
    } void setMyDate(int MyDate)//相同方法出现两次 {
    this.MyDate = MyDate;
    }}public class TestStudent{
    public static void main(String args[])    { Student stu = new Student("0401398", "廖小明", 200891,20);      System.out.println("student info: " + "\n学号:"+stu.getId()+ "\n姓名:"+    stu.getName()+"\n出生日期:"+stu.getMyDate()+ "\n年龄:"+stu.getAge());      stu.setAge(19);
        stu.setMyDate(200891); 
        
        System.out.println("修改后的年龄为:"+stu.getAge());    }}出生日期有Date类型不要用int型
      

  2.   

    第一个问题:
    你的setXXX()方法和getXXX()方法与属性是否对应。你有两个setAge(int age)方法,
    缺少setId(),getId(),setName(),getName()
    第二个问题
    你在TestStudent类中有new来实例化Student类,但是没有相应的构造方法
    第三个问题
    你的属性的类型不统一
    你在类定义时,MyDate属性类型为int类型,但在下面实例化时,你缺却用String类型
      

  3.   


    import java.util.*;class mystudent{   private String id;    private String name;   private Date MyDate;   private int age;       
      public mystudent(String id,String name,Date dt,int age){
      this.id=id;
      this.name=name;
      this.age=age;
      this.MyDate=dt;
      }
      public String getId()
      {
      return  id; 
      }   public String getName()   { return name;  }   public Date getMyDate()
      {
      return MyDate; 
      }   public int getAge()   { return age;  }   void setAge(int age)   { this.age = age;  }   void setMyDate(Date MyDate)   { this.MyDate = MyDate;  }
     }
      public class test {
      public static void main(String args[])
      { 
      //Date dt=new Date();
      mystudent stu = new mystudent("0401398", "廖小明", new Date(2008,9,1),20);System.out.println("student info: " + "\n学号:"+stu.getId()+ "\n姓名"+stu.getName()+"\n性别:"+stu.getMyDate()+ "\n年龄:"+stu.getAge());
    stu.setAge(19);
    stu.setMyDate(new Date(2008,9,1));
    System.out.println("修改后的年龄为:"+stu.getAge());   }   } 
      

  4.   

    三楼朋友也没有写全,缺少setId()和setName()方法
      

  5.   

    楼上正解,另外没有构造函数,像楼上那样写一个构造函数。
    不过楼主的情况最好还是写成标准的javaBean,无参构造函数加setter和getter方法即可。
      

  6.   

    错误挺多的哦,首先你没有构造方法,却在主函数中用到了student stu = new student("0401398", "廖小明", "2008 9 1",20); 这是肯定错误的,还有。
      

  7.   

    按照你那个编译CMD显示是NOTe: test.java uses or overrides a deprecated API.
    note:recompile with -Xlint:deprecation for details.是什么意思??不懂
      

  8.   

    class Student{   private String id;    private String name;   private String MyDate;   private int age; 
      public student(String id , String name , String MyDate , int age){
       this.id = id;
       this.name = name;
       this.MyDate = MyDate ;
       this.age = age;
       }         public String getId()   {return  id;  }   public String getName()   { return name;  }   public String getMyDate()   { return MyDate;  }   public int getAge()   { return age;  }   void setAge(int age)   { this.age = age;  }   void setMyDate(String MyDate)   { this.MyDate = MyDate;  } 
      } 
      public class TestStudent {
        
        public static void main(String args[]) {
        
          student stu = new student("0401398", "廖小明", "2008 9 1",20);     System.out.println("student info: " + "\n学号:"+stu.getId()+ "\n姓名"+       stu.getName()+"\n性别:"+stu.getMyDate()+ "\n年龄:"+stu.getAge());         stu.setAge(19);stu.setMyDate("2008 9 1"); 
         System.out.println("修改后的年龄为:"+stu.getAge());   }   } 
    ok!
      

  9.   

    没构造方法,2个setAge(),是copy后忘了改方法名么?我也初学,我觉得开始没必要为类写那么多的属性,写1-2个就好了,搞清楚意义更重要