import java.util.*;
import java.io.*;
public class Employee{
public String emp_name;
public int emp_id;
public double emp_salary;
public int emp_phone;
public Employee(String add_newName, int add_newID, double add_newSalary, int add_newPhone){
emp_name = add_newName;
emp_id = add_newID;
emp_salary = add_newSalary;
emp_phone = add_newPhone;
}
public Employee(int add_ID, int add_Phone){
emp_name = "NULL";
emp_id = add_ID;
emp_salary = 0;
emp_phone = add_Phone;
}
public double increaseSalary(double increase_amt){
return emp_salary += increase_amt;
}
public String getName(){
return emp_name;
}
public String toString(){
return "Name of employee: " + emp_name + ",, " + "ID number of employee: " + emp_id + ",, " + "Employee salary: " + emp_salary + ",, " + "Employee phone: " + emp_phone;
}
public static void process(){
Employee employee1 = new Employee(noel, 101, 5050.50, 1230987);
Employee employee2 = new Employee(102, 5672389);
System.out.println("Employee Information: " + employee1.toString());
}
public static void main(String args[]){
process();
}
}
错误是在进程方法中,你看到noel,java说找不到它的符号......求助?
答案 0 :(得分:3)
将noel
更改为"noel"
Employee employee1 = new Employee("noel", 101, 5050.50, 1230987);
没有""
java会将其视为变量
答案 1 :(得分:2)
Java中String
的语法是:
"Some String"
请注意双引号。要解决您的问题,您必须写"noel"
。
Employee employee1 = new Employee("noel", 101, 5050.50, 1230987);
答案 2 :(得分:1)
您通过传递noel创建员工
Employee employee1 = new Employee(noel, 101, 5050.50, 1230987);
它应该是String as:
Employee employee1 = new Employee("noel", 101, 5050.50, 1230987);