无法访问对象属性java
这里有许多问题无法访问对象属性java,java,object,properties,Java,Object,Properties,这里有许多问题 您正在肆意拼错属性名称 您在for each语句中使用了对象,您应该在其中使用员工 您试图直接从类外部访问的字段被声明为private,这意味着您无法访问。您应该使用相应的访问器函数 “it't not let me”是什么意思?另外,sallay的拼写是否没有r,或者这是一个拼写错误?寻求调试帮助的问题(“为什么这个代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:。您提到您的Emplo
对象
,您应该在其中使用员工
private
,这意味着您无法访问。您应该使用相应的访问器函数“it't not let me”是什么意思?另外,
sallay
的拼写是否没有r
,或者这是一个拼写错误?寻求调试帮助的问题(“为什么这个代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:。您提到您的Employeee
类有getter和setter。你为什么不使用它们来获得你想要的属性呢?当然有帮助。当然,这会对邮报产生影响。别傻了。
List<Employeee> employees = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
String[] input = new String[6];
int n = Integer.valueOf(scanner.nextLine());
for (int i = 0; i < n; i++) {
input = scanner.nextLine().split(" ");
employees.add(new Employeee(input[0], Double.parseDouble(input[1]), input[2], input[3], input[4],
Integer.valueOf(input[5])));
}
for (Object i : employees) {
System.out.println(i.sallary); //And here ofc idk what to do to print them
System.out.println(i.name);
}
public class Employeee {
private String name;
private double sallary;
private String possition;
private String department;
private String email;
private int age;
public Employeee(String name, double sallary, String possition, String department, String email, int age) {
this.name = name;
this.sallary = sallary;
this.possition = possition;
this.department = department;
this.email = email;
this.age = age;
}
}