这条java代码行做什么
在这里,我想获取员工数据并对其进行计算,然后打印出来。 但是使用line这条java代码行做什么,java,object,Java,Object,在这里,我想获取员工数据并对其进行计算,然后打印出来。 但是使用lineEmployee emp=getEmployeeDetails()不是我所理解的 public static void main(String [] args){ Employee emp = getEmployeeDetails(); //THIS LINE// System.out.println("Id : "+emp.getEmployeeId()); System.out.println("
Employee emp=getEmployeeDetails()代码>不是我所理解的
public static void main(String [] args){
Employee emp = getEmployeeDetails(); //THIS LINE//
System.out.println("Id : "+emp.getEmployeeId());
System.out.println("Name : "+emp.getEmployeeName());
System.out.println("Salary : "+emp.getSalary());
System.out.println("Net Salary : "+emp.getNetSalary());
}
public static Employee getEmployeeDetails(){
Scanner scan = new Scanner(System.in);
Employee emp = new Employee();
System.out.println("Enter id:");
emp.setEmployeeId(scan.nextInt());
scan.nextLine();
System.out.println("Enter Name:");
emp.setEmployeeName(scan.nextLine());
System.out.println("Enter salary:");
emp.setSalary(scan.nextDouble());
//scan.close();
return emp;
}
在代码中有一个名为getEmployeeDetails
的方法,它返回Employee
的实例
这一行所做的是获取方法执行返回的实例,并将其分配给名为emp的Employee类型的新变量。嗯,这只是一个方法调用,也是这样写的另一种方式:
publicstaticvoidmain(字符串[]args){
//Employee emp=getEmployeeDetails();//此行//
扫描仪扫描=新扫描仪(System.in);
员工emp=新员工();
System.out.println(“输入id:”);
emp.setEmployeeId(scan.nextInt());
scan.nextLine();
System.out.println(“输入名称:”);
emp.setEmployeeName(scan.nextLine());
System.out.println(“输入薪资:”);
emp.setSalary(scan.nextDouble());
//scan.close();
System.out.println(“Id:+emp.getEmployeeId());
System.out.println(“名称:”+emp.getEmployeeName());
System.out.println(“Salary:+emp.getSalary());
System.out.println(“净工资:+emp.getNetSalary());
}
您对它了解多少?为什么你认为这是不同的?共享员工类别代码