标题: 请问为什么会出错误 [打印本页] 作者: coco2016 时间: 2016-7-11 16:30 标题: 请问为什么会出错误 代码如下,为什么会出现在。java的文件中申明错误,请大神指点下,谢谢!
public class Demo_Employee {
public static void main(String[] args)
{
Manager m = new Manager("张三","9547",2000);
m.work();
m.Bonus("50000");
System.out.println(m.getName()+"...."+m.getId()+"...."+m.getSalary());
Coder c = new Coder("","9875",5000);
c.work();
System.out.println(c.getName()+"...."+c.getId()+"...."+c.getSalary());
}
}
/*
雇员类
工资 salary 姓名 name 工号 id
*/
public abstract class Employee
{
private String name;
private String id;
private double salary;
public Employee(){}
public Employee(String name,String id,double salary){
this.name = name;
this.id = id;
this.salary = salary;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setId(String id){
this.id = id;
}
public String getId(){
this.id = id;
}
public void setSalary(double salary){
this.salary = salary;
}
public double getSalary(){
return salary;
}
public abstract void work();
}
/*
manager类
工作为管理
*/
public class Manager extends Employee{
private String bonus;
public Manager(){}
public Manager(String name,String id,double salary){
super(name,id,salary);
}
public void work(){
System.out.println("我的名字是:"+getName()+",我的工号是:"+getId()+",我的工资是:"+getSalary());
}
//public void Bonus(){}
public String Bonus(){
this.bonus = bonus;
}
public void setBonus(String bonus){
this.bonus = bonus;
}
public String getBonus(){
return bonus;
}
public void Bonus(String bonus){
System.out.println("奖金");
}
}
/*
coder类
工作为写代码
*/
public class Coder extends Employee{
public Coder(){}
public Coder(String name,String id,double salary){
super(name,id,salary);
}
public void work(){
System.out.println("我的名字是:"+getName()+",我的工号是:"+getId()+",我的工资是:"+getSalary());
}
}请大神指点下,谢谢
你的抽象类和子类都加了 public。解释:java语法规范中一个java类中只能有一个public class,不能出现多个,否则会直接报错,无法进行正常编译的。
备注:如果想进行多个class方法调用,建议创建多个class类文件的形式实现,要通过一个java文件实现是没法做到的。public class A {}
class B {}
class C {}