java问题,我按着书上写的,一点没错,为什么软件提示有错误呢
classStudent{//提示已经定义类型StudentStringname;intage;publicStudent(){}publicStudent(String...
class Student{ //提示已经定义类型Student
String name;
int age;
public Student(){}
public Student(String n, int a){
this.name = n;
this.age = a;
}
public String out(){
return "name is " + name + " \t age is " + age;
}
}
public class TestObjectArray {
public static void main(String args []){
Student p [] = {new Student("ZhangSan",34),new Student("LiSi",32)};
int i = 0;
while(i < p.length){
System.out.println(p[i].out());
i++;
}
}
} 展开
String name;
int age;
public Student(){}
public Student(String n, int a){
this.name = n;
this.age = a;
}
public String out(){
return "name is " + name + " \t age is " + age;
}
}
public class TestObjectArray {
public static void main(String args []){
Student p [] = {new Student("ZhangSan",34),new Student("LiSi",32)};
int i = 0;
while(i < p.length){
System.out.println(p[i].out());
i++;
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询