public class TestEmployee{
public static void main(String[] args){
SalaryEmployee e1=new SalaryEmployee("zhao jun",2000.0,4);
System.out.println(e1.getSalary(4));
}
}
class Employee{
private String name;
private int month;
public Employee(String name,int month){
this.name=name;
this.month=month;
}
public double getSalary(int month){
return 0.0;
}
public int getMonth(){
return this.month;
}
}
class SalaryEmployee{
private double salary;
public SalaryEmployee(String name,double salary,int month){
super(name,month);
this.salary=salary;
}
public double getSalary(int month){
if(super.getMonth()==month){
return salary+100.0;
}
else return salary;
}
}
如上代码,编译时即出现错误,请高手指点!
public static void main(String[] args){
SalaryEmployee e1=new SalaryEmployee("zhao jun",2000.0,4);
System.out.println(e1.getSalary(4));
}
}
class Employee{
private String name;
private int month;
public Employee(String name,int month){
this.name=name;
this.month=month;
}
public double getSalary(int month){
return 0.0;
}
public int getMonth(){
return this.month;
}
}
class SalaryEmployee{
private double salary;
public SalaryEmployee(String name,double salary,int month){
super(name,month);
this.salary=salary;
}
public double getSalary(int month){
if(super.getMonth()==month){
return salary+100.0;
}
else return salary;
}
}
如上代码,编译时即出现错误,请高手指点!
class SalaryEmployee extends Employee {.......
....
SalaryEmployee类应该继承Employee类。
LZ漏写了 extends 关键字。
return salary+100.0;
} 是这里有错 super关键字是用在继承上的,朋友可能是初学吧,这些不太明白也是正常的,多看看网上的视频吧比看书来的容易!!!
起码在Employee里还要加个public Employee(){}