日期:2014-05-20  浏览次数:20714 次

如此简单的问题,马上给分
public class Example{
public static void main(String[] args){
System.out.println("Testing tripvalue:");
double percent=10;
System.out.println("before:"+percent);
tripvalue(percent);
System.out.println("after:"+percent);

System.out.println("************************");
System.out.println("Testing tripleSalary :");
Employee bob=new Employee("bob",5000);
System.out.println("before:"+bob.getSalary());
bob.raiseSalary(15);
System.out.println("after:"+bob.getSalary());

}
public static void tripvalue(double x)
{
x=3*x;
System.out.println("x is :"+x);
}
}

class Employee //这里提示“the type Employee is already defined”
{
public Employee(String n,double s)
{
this.name=n;
this.salary=s;

}
public String getName(){
return name;
}
public double getSalary(){
return salary;
}
public void raiseSalary(double byPercent)
{
double raise=salary * byPercent /100;
salary+=raise;
}
private String name;
private double salary;
}

-----------------
class Employee //这里提示“the type Employee is already defined”
就是这句出的问题,java2核心技术的例子

------解决方案--------------------
同一个类被定义了两次。
------解决方案--------------------
因为你的这个类没有包名 如果你在其他地方(但是要在这个文件夹下)定义一个同名的类,就会这样。
------解决方案--------------------
class Employee //这里提示“the type Employee is already defined” 
重复定义了呀
------解决方案--------------------
the type Employee is already defined说的很明白了,已经定义了类,
我想问问你的
this.name=n; 
this.salary=s;
在哪定义的?