staff[0] = new Employee("wzy1",35000);
类型不一致,staff[0]是 EmployeeSortTest类型

解决方案 »

  1.   

    同意 blackrye 所说的, EmployeeSortTest 和 Employee 是两个完全不同的类型,两者之间也没有继承的关系。
      

  2.   

    >>>>EmployeeSortTest[] staff = new EmployeeSortTest[3];改为
       Employee[] staff = new Employee[3];
      

  3.   

    import java.awt.*;
    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() ;
        }
      }
    }
      

  4.   

    改成这样?
        Employee[] staff = new Employee[3];
        staff[0]= ("wzy1",35000);
        staff[1] = ("wzy2",75000);
        staff[2] = ("wzy3",38000);
      

  5.   

    求哪位给我改一下完整的代码~~~
    大家都推荐的java核心技术第六版里面的代码也会有错?
      

  6.   

    改成:
        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);
      

  7.   

    import java.awt.*;
    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() ;
        }
      }
      

  8.   

    import java.util.*;public class EmployeeSortTest extends Employ{
      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;
    }
      

  9.   

    请问为什么会出现non-static variable this cannot be referenced from a static context
    这个错误?
      

  10.   

    to  classjava(原始野人) :
    为什么一定要继承呢?