悟
悟峰
Unregistered / Unconfirmed
GUEST, unregistred user!
JC環境,代碼如下:
class customer
{
String custname;
String custno;
String custsex;
int custage;
public void displaydetails()
{
System.out.println(custname);
System.out.println(custno);
System.out.println(custsex);
System.out.println(custage);
}
}
class customerexample
{
customer custobject[];
public customerexample()
{
custobject=new customer;
for (int ctr=0;ctr!=3;ctr++)
{
custobject[ctr]=new customer();
}
custobject[0].custname="悟峰";
custobject[0].custno="3427";
custobject[0].custsex="男";
custobject[0].custage=27;
}
public void displayCollection()
{
try
{
for(int ctr=0;ctr!=4;ctr++)
{
custobject[ctr].displaydetails();
}
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("Trying to access beyond the length of the array");
}
}
public static void main(String args[])
{
customerexample collectionobj;
collectionobj=new customerexample();
collectionobj.displayCollection();
System.out.println("All records displayed");
}
}
錯誤信息如下,搞不明白為什么:
--------------------Configuration: customerExample - JDK version 1.3.1_04 <Default>--------------------
C:/Program Files/Xinox Software/JCreator Pro/MyProjects/Helloworld3/variableclass/customer/cathcdemo/customerExample/CustomerExample.java:31: '(' or '[' expected
custobject=new customer;
^
1 error
Process completed.
class customer
{
String custname;
String custno;
String custsex;
int custage;
public void displaydetails()
{
System.out.println(custname);
System.out.println(custno);
System.out.println(custsex);
System.out.println(custage);
}
}
class customerexample
{
customer custobject[];
public customerexample()
{
custobject=new customer;
for (int ctr=0;ctr!=3;ctr++)
{
custobject[ctr]=new customer();
}
custobject[0].custname="悟峰";
custobject[0].custno="3427";
custobject[0].custsex="男";
custobject[0].custage=27;
}
public void displayCollection()
{
try
{
for(int ctr=0;ctr!=4;ctr++)
{
custobject[ctr].displaydetails();
}
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("Trying to access beyond the length of the array");
}
}
public static void main(String args[])
{
customerexample collectionobj;
collectionobj=new customerexample();
collectionobj.displayCollection();
System.out.println("All records displayed");
}
}
錯誤信息如下,搞不明白為什么:
--------------------Configuration: customerExample - JDK version 1.3.1_04 <Default>--------------------
C:/Program Files/Xinox Software/JCreator Pro/MyProjects/Helloworld3/variableclass/customer/cathcdemo/customerExample/CustomerExample.java:31: '(' or '[' expected
custobject=new customer;
^
1 error
Process completed.