staff[0] = new Employee("wzy1",35000);
类型不一致,staff[0]是 EmployeeSortTest类型
类型不一致,staff[0]是 EmployeeSortTest类型
解决方案 »
- getDate()-getDate()等于多少
- 怎么把路径中文件名去掉?
- SessionBean和javabean的区别
- 求助!高手请指教:一段关于java.io文本输入的程序,为何不能运行?急死我拉!
- java中static方法问题
- 如何获取JTextArea中当前光标的位置?
- why my code is wrong
- 什么叫 base64编码?原理是什么啊?
- 急!请教高手!如何给一个button设置热键
- 如何使用socket,在C/S程序之间传递数组?
- java.lang.IllegalStateException: getOutputStream() 出错
- 大家进来看看啊!到底是哪不对啊??
Employee[] staff = new Employee[3];
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;public class TimerTest {
public static void main (String[] args){
ActionListener listener= new TimePrinter();//这里的new也出错.......
Timer t=new Timer(10000,listener);
t.start();
JOptionPane.showMessageDialog(null,"quit program?");
System.exit(0);
}
class TimePrinter implements ActionListener{
public void actionPerformed(ActionEvent event){
Date now =new Date();
System.out.println("at the tone,the time is "+now);
Toolkit.getDefaultToolkit().beep() ;
}
}
}
Employee[] staff = new Employee[3];
staff[0]= ("wzy1",35000);
staff[1] = ("wzy2",75000);
staff[2] = ("wzy3",38000);
大家都推荐的java核心技术第六版里面的代码也会有错?
Employee[] staff = new Employee[3];
staff[0]= new Employee("wzy1",35000);//还是有错:non-static variable this cannot be referenced from a static context staff[1] = new Employee("wzy2",75000);
staff[2] = new Employee("wzy3",38000);
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;public class Test extends TimePrinter {
public static void main (String[] args){
ActionListener listener= new TimePrinter();//这里的new也出错.......
Timer t=new Timer(10000,listener);
t.start();
JOptionPane.showMessageDialog(null,"quit program?");
System.exit(0);
}}
class TimePrinter implements ActionListener{
public void actionPerformed(ActionEvent event){
Date now =new Date();
System.out.println("at the tone,the time is "+now);
Toolkit.getDefaultToolkit().beep() ;
}
}
public static void main(String[] args){
EmployeeSortTest[] staff = new EmployeeSortTest[3];
staff[0] = new Employee("wzy1",35000); staff[1] = new Employee("wzy2",75000);//这里也一样
staff[2] = new Employee("wzy3",38000);//这里也一样 Arrays.sort(staff);
for (int i=0;i<staff.length ;i++){
Employee e=staff[i];
System.out.println("name="+e.getName()+",salary="+e.getSalary());
}
}}
class Employee implements Comparable{
public Employee (String n,double s){
name=n;
salary=s;
}
public String getName(){
return name;
}
public double getSalary(){
return salary;
}
public void raiseSalary(double byPercent){
double raise=salary*byPercent/100;
salary+=raise;
}
public int compareTo(Object otherObject) {
Employee other=(Employee)otherObject;
if (salary<other.getSalary()) return -1;
if (salary>other.getSalary()) return 1;
return 0;
}
private String name;
private double salary;
}
这个错误?
为什么一定要继承呢?