Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这条java代码行做什么_Java_Object - Fatal编程技术网

这条java代码行做什么

这条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("

在这里,我想获取员工数据并对其进行计算,然后打印出来。 但是使用line
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());
}

您对它了解多少?为什么你认为这是不同的?共享员工类别代码