无法编译Java代码。请检查

时间:2019-06-13 07:57:33

标签: java

我无法编译以下代码,请您帮忙。

我尝试编译,但出现以下错误。

  

Temp.java:18:错误:类Employee中的构造函数Employee不能为   适用于给定的类型;           雇员e1 =新雇员(“ Venu”,101,34000.00);                         ^必需:未找到参数:字符串,整数,双精度原因:实际参数和形式参数列表的不同   长度

import java.util.*;

class Employee {
    public String name;
    public int empId;
    public double salary;

    public void Employee(String name, int empId, double salary) {
        this.name = name;
        this.empId = empId;
        this.salary = salary;
    }
}

public class Temp {

    Employee e1 = new Employee("Venu", 101, 34000.00);
    Employee e2 = new Employee("Krishna", 102, 22000.00);
    Employee e3 = new Employee("Gopal", 103, 18000.00);
    Employee e4 = new Employee("ramya", 104, 10000.00);
    Employee e5 = new Employee("sonia", 105, 50000.00);

    public static void main(String args[]) {
        Temp t = new Temp();
        ArrayList<Employee> al = new ArrayList<Employee>();
        al.add(t.e1);
        al.add(t.e2);
        al.add(t.e3);
        al.add(t.e4);
        al.add(t.e5);

        for(Employee emp : al) {
            System.out.println(emp.name + emp.salary);
        }
    }
}

0 个答案:

没有答案