首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

如此简单的有关问题,马上给分

2011-12-27 
如此简单的问题,马上给分public class Example{public static void main(String[] args){System.out.print

如此简单的问题,马上给分
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;
在哪定义的?

热点排行