小程序有小错误
class P22{
int id;
String name;
int age;
boolean sex;
String phone;
P22(int id,String name,int age,boolean sex,String phone)
{
this.id=id;
this.name=name;
this.age=age;
this.sex=sex;
this.phone=phone;
}
public int getAge()
{
return age;
}
public int getId()
{
return id;
}
public String getName()
{
return name;
}
public String getSex()
{
if(sex==true)
{
return new String("boy");
}
else
{
return new String("girl");
}
}
public long getPhone()
{
return Long.parseLong(phone);
}
public String toString()
{
String st=name+":"+phone;
return st;
}
}
public class Ti
{
public static void main(String args[])
{
Student a[]=new Student[1];
a[0]=new Student(12,"李四",21,true,12345678);
a[1]=new Student(12,"张三",21,true,12345678);
for(int i=0;i<a.length;i++)
{
System.out.println("学号"+a[i].getId()+"姓名:"+a[i].getName()+"年龄:"+
a[i].getSex()+"电话:"+a[i].getPhone());
}
}
}