问题链接:http://club.edu5a.com/showtopic-245724.html
package zm.dmy6;
public class Stu {
public static void main(String[] args) {
student1[] std = new student1[3];//构造了一个student1类的一维数组
int i = 0;
for (i = 0; i < 3; i++)
{
std[i] = new student1(); //没有这句就错了空指针异常,数组元素也是对象,也是要new的
std[i].InputData();
}
for (i = 0; i < 3; i++)
{
std[i].ShowData();
}
}
}
class student1 {
public void InputData()
{
System.out.println("ccccc");
}
public void ShowData() {
System.out.println("aaaa");
}
}