public class credentials {       //证件类
private int No;
private String name;
private boolean sex;
private date birthday;

public credentials (int No,String name,boolean sex,date birthday){
this.No = No;
this.name = name;
this.sex = sex;
this.birthday =birthday ;
}

public int getNo() {return No;}
public String getName() {return name;}
public boolean getSex() {return sex;}
public date getBirthday() {return birthday;}


  public String toString() {
 
return "\nNo:" + No + "\tName:" + name + "\tSex:" + sex + "\tBirthday:" + 
birthday.getY() + "-" + birthday.getM() + "-" + birthday.getD();

解决方案 »

  1.   


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

    date T = new date(2010,11,8);
    credentials A = new credentials(1000,"证件",true,T);
    System.out.println("证件信息:");
    A.toString();
    }
    }
      

  2.   


    A.toString();        
    你只调用了toString方法又没有输出!
      

  3.   


    System.out.println("证件信息:  "+A.toString());
      

  4.   

    晕死!
     System.out.println("证件信息:");
            A.toString();        改成 System.out.println("证件信息:" + A.toString());
            
      

  5.   

    toString 只是对属性进行了拼装而没有进行输出操作。
      

  6.   

    public static void main(String[] args) {
              
              Date T = new Date(2010,11,8);
              credentials A = new credentials(1000,"证件",true,T);
              System.out.println("证件信息:");
              System.out.println(A.toString());        
          }
      

  7.   

    G啊,你的程序能运行??public String toString() {
         
            return "\nNo:" + No + "\tName:" + name + "\tSex:" + sex + "\tBirthday:" + 
                    birthday.getY() + "-" + birthday.getM() + "-" + birthday.getD();
        } 
    我该了一下,这个能运行
    import java.util.Date;
    class credentials {       //证件类
        private int No;
        private String name;
        private boolean sex;
        private Date birthday;    public credentials (int No,String name,boolean sex,Date birthday){
            this.No = No;
            this.name = name;
            this.sex = sex;
            this.birthday =birthday ;
        }      public void PrintC() {
           System.out.println("\nNo:" + this.No + "\tName:" + this.name + "\tSex:" + this.sex + "\tBirthday:" +this.birthday);
          }
    }public class TestCredentials {    public static void main(String[] args) {        Date T = new Date(2010,11,8);
            credentials A = new credentials(1000,"证件",true,T);
            System.out.println("证件信息:");
            A.PrintC();
        }
    }