public class Student//java:1: 错误: 类Student是公共的, 应在名为 Student.java 的文件中声明
public class Student
{
private String name;
public Student(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class TestDemo
{
public static void main(String[] args)
{
Student[] s = new Student[2];//定义Student数组对象
s[0] = new Student("张三");
s[1] = new Student("李四");
int i=0;
for(Student st : s)
{
System.out.println("姓名:"+st.getName()+ i++);
}
}
}
|
|