How to instantiante object & call setter on same line?

前端 未结 8 1300
一个人的身影
一个人的身影 2020-12-10 10:49

If I have an Employee class with a default constructor:

private String firstName;
public Employee(){}

and a setter:

         


        
8条回答
  •  无人及你
    2020-12-10 11:24

    It should be like this:

    Employee employee = new Employee();
    employee.setFirstName("John");
    

提交回复
热议问题