Topic: 一个急待解决的问题(《JAVA核心技术》中的实例)

  Print this page

1.一个急待解决的问题(《JAVA核心技术》中的实例) Copy to clipboard
Posted by: gna15
Posted on: 2006-07-13 11:39

class Employee
{
public Employee(String n,double s)
{
name=n;
salary=s;
System.out.println("two parameters 222");
}
public Employee(double s)
{
this("Employee#"+nextld,s);
System.out.println("one parameter 111");
}
public Employee()
{
System.out.println("no parameter 000");
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public int getId()
{
return id;
}
private String name="";
private double salary;
private int id;
private static int nextId;
{
System.out.println("initalization");
nextId++;
}
static
{
System.out.println("static initalization");
Random generator=new Random();
nextId=generator.nextInt(10000);
}
}
public class ConstructorTest
{
public static void main(String args[])
{
Employee[] staff=new Employee[3];
staff[0]=new Employee("Harry",40000);
staff[1]=new Employee(60000);
staff[2]=new Employee();
}
for(int i=0;i<staff.length;i++)
{
Employee e=staff[i];
System.out.println("name="+e.getName()+",id="+e.getId()+",salary="+e.getSalary());
}

}
那位高手帮忙看看是哪的毛病,先谢过了

2.Re:一个急待解决的问题 [Re: gna15] Copy to clipboard
Posted by: Skybus
Posted on: 2006-07-13 15:28

楼主遇到什么问题

3.Re:一个急待解决的问题 [Re: gna15] Copy to clipboard
Posted by: blueshoot
Posted on: 2006-07-13 18:41

this("Employee#"+nextld,s);其中nextld应该写成nextId;
Random generator=new Random(); 在程序开头插入:import java.util.*;

"}
for(int i=0;i<staff.length;i++)
{
Employee e=staff[i];
System.out.println("name="+e.getName()+",id="+e.getId()+",salary="+e.getSalary());
}"这段代码开头的“}”是否写错?应该写成:

for(int i=0;i<staff.length;i++)
{
Employee e=staff[i];
System.out.println("name="+e.getName()+",id="+e.getId()+",salary="+e.getSalary());
}
}

4.Re:一个急待解决的问题 [Re: gna15] Copy to clipboard
Posted by: wqq0712
Posted on: 2006-07-14 21:34

楼上的说的“}”问题 我没看懂!是什么意思?这个程序我调试了也是出现这问题!不知道怎么解决~~能说清楚点?

5.Re:一个急待解决的问题 [Re: gna15] Copy to clipboard
Posted by: gna15
Posted on: 2006-08-18 11:50

kokokokoko

6.Re:一个急待解决的问题 [Re: wqq0712] Copy to clipboard
Posted by: why
Posted on: 2006-08-18 12:06

wqq0712 wrote:
楼上的说的“}”问题 我没看懂!是什么意思?这个程序我调试了也是出现这问题!不知道怎么解决~~能说清楚点?

from

public class ConstructorTest
{
public static void main(String args[])
{
Employee[] staff=new Employee[3];
staff[0]=new Employee("Harry",40000);
staff[1]=new Employee(60000);
staff[2]=new Employee();
}
for(int i=0;i<staff.length;i++)
{
Employee e=staff[i];
System.out.println("name="+e.getName()+",id="+e.getId()+",salary="+e.getSalary());
}

}

to

public class ConstructorTest {
public static void main(String args[]) {
Employee[] staff = new Employee[3];
staff[0] = new Employee("Harry", 40000);
staff[1] = new Employee(60000);
staff[2] = new Employee();
//}
for (int i = 0; i < staff.length; i++) {
Employee e = staff[i];
System.out.println("name=" + e.getName() + ",id=" + e.getId() + ",salary=" + e.getSalary());
}

} //added
}

7.Re:一个急待解决的问题 [Re: gna15] Copy to clipboard
Posted by: leange
Posted on: 2006-08-18 13:45

这段代码好像是《JAVA核心技术》中的实例,楼主按着教材敲都这么多错误的??


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923