我对 java 编程语言很陌生,我真的很想帮助理解下面的代码在做什么。我对 Main 类中发生的事情有相当不错的理解。我的问题是“this._”在代码中的作用。名称究竟是如何转移的?这不是家庭作业,只是自学。练习可以在这里找到:http: //www.learnjavaonline.org/Functions另外,建议阅读会很棒!谢谢!
class Student {
private String firstName;
private String lastName;
public Student(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public void printFullName(){
System.out.println(this.firstName+" "+this.lastname);
}
}
public class Main {
public static void main(String[] args) {
Student[] students = new Student[] {
new Student("Morgan", "Freeman"),
new Student("Brad", "Pitt"),
new Student("Kevin", "Spacey"),
};
for (Student s : students) {
s.printFullName();
}
}
}