当前位置: 代码迷 >> Java相关 >> 新手小问题 错误找不到符号 构造函数Person p2=new Person
  详细解决方案

新手小问题 错误找不到符号 构造函数Person p2=new Person

热度:644   发布时间:2012-02-28 10:31:59.0
新手小问题 错误找不到符号 构造函数Person p2=new Person
public class Person{
private int age=0;
private String name="noname";
private char sex='M';
public Person(String n,int a,char s){
         name=n;
         if(a>=0&&a<140) age=a;
         else age=0;
         if(s=='M') sex=s;
         else sex='F';
}
public void introduceme(){
     System.out.println("my name is:"+name+"\tmy age is :"+age);
     if(sex=='M') System.out.println("i an man!");
     else System.out.println("i am woman!");
}
     public String getName(){return name;}
     public void setName(String n){name=n;}
     public int getAge(){return age;}
     public void setAge(int a){
         if(a>=0&&a<140) age=a;
         else age=0;
     }
     public char getSex(){return sex;}
     public void setSex(char s){
         if(s=='M') sex='M';
         else sex='F';
     }
     public boolean equals(Person a){
         if(this.name.equals(a.name)&&this.age==a.age&&this.sex==a.sex)
             return true;
         else
             return false;
     }
     public String toString(){
         return name+","+sex+","+age;
     }
}
class PersonTest
{
     public static void main(String args[]){
         Person p1,p2;
         p1=new Person("张三",28,'M');
         p2=new Person();
         p2.setName("陈红");
         p2.setAge(38);p2.setSex('F');
         p1.introduceme();
         p2.introduceme();
     }
}
搜索更多相关的解决方案: class  private  public  return  

----------------解决方案--------------------------------------------------------
没有默认的构造函数。
----------------解决方案--------------------------------------------------------
谢谢 知道问题了 我是新手 以后还多多指教!
----------------解决方案--------------------------------------------------------
  相关解决方案