当前位置: 技术问答>java相关
一个关于数组的问题,谢谢
来源: 互联网 发布时间:2015-07-01
本文导语: class Applicant { String applicantName; String applicantAddress; String applicantPosition; public void displayDetails() { System.out.println(applicantName); System.out.println(applicantAddress); System.out.println(applicantPosition); } } public class ApplicantCol...
class Applicant
{
String applicantName;
String applicantAddress;
String applicantPosition;
public void displayDetails()
{
System.out.println(applicantName);
System.out.println(applicantAddress);
System.out.println(applicantPosition);
}
}
public class ApplicantCollection
{
Applicant appObjects[];
public void ApplicantCollection()
{
appObjects =new Applicant[3];
for (int ctr=0;ctr!=appObjects.length;ctr++)
{
appObjects[ctr]=new Applicant();
}
appObjects[0].applicantName="Tom";
appObjects[0].applicantAddress="1 Park Avenue";
appObjects[0].applicantPosition="Manager";
appObjects[1].applicantName="Jim";
appObjects[1].applicantAddress="21 Bakers St";
appObjects[1].applicantPosition="Executive";
appObjects[2].applicantName="Peter";
appObjects[2].applicantAddress="63 Brown Stone";
appObjects[2].applicantPosition="Associate";
}
public void displayCollection()
{
for (int ctr=0;ctr!=appObjects.length;ctr++)
{
appObjects[ctr].displayDetails();
}
}
public static void main(String args[])
{
ApplicantCollection collectionObject;
collectionObject=new ApplicantCollection();
collectionObject.displayCollection();
}
}
javac可以通过,但是java有错,帮忙看看
{
String applicantName;
String applicantAddress;
String applicantPosition;
public void displayDetails()
{
System.out.println(applicantName);
System.out.println(applicantAddress);
System.out.println(applicantPosition);
}
}
public class ApplicantCollection
{
Applicant appObjects[];
public void ApplicantCollection()
{
appObjects =new Applicant[3];
for (int ctr=0;ctr!=appObjects.length;ctr++)
{
appObjects[ctr]=new Applicant();
}
appObjects[0].applicantName="Tom";
appObjects[0].applicantAddress="1 Park Avenue";
appObjects[0].applicantPosition="Manager";
appObjects[1].applicantName="Jim";
appObjects[1].applicantAddress="21 Bakers St";
appObjects[1].applicantPosition="Executive";
appObjects[2].applicantName="Peter";
appObjects[2].applicantAddress="63 Brown Stone";
appObjects[2].applicantPosition="Associate";
}
public void displayCollection()
{
for (int ctr=0;ctr!=appObjects.length;ctr++)
{
appObjects[ctr].displayDetails();
}
}
public static void main(String args[])
{
ApplicantCollection collectionObject;
collectionObject=new ApplicantCollection();
collectionObject.displayCollection();
}
}
javac可以通过,但是java有错,帮忙看看
|
你的构造函数写错了,那个不是构造函数,不应该有返回值!你把那个void去掉就可以了!
|
去掉public void ApplicantCollection()的void,构造是没有返回值的。没调用到构造!
|
public void ApplicantCollection()
应为pubic ApplicantCollection()
应为pubic ApplicantCollection()
|
哈哈,真是大意失荆洲! :) 加油!