gpt4 book ai didi

java - 哪种做法更好?关于构造函数

转载 作者:行者123 更新时间:2023-11-29 07:44:27 25 4
gpt4 key购买 nike

<分区>

哪种做法更好,风格明智?使用关键字“this”或为构造函数的参数选择不同的参数名称?

案例一:

public class Student {
//variables
private String name;

//constructor
public Student(String name) {
this.name = name;
}
}

或情况 2:

public class Student {
//variables
private String name;

//constructor
public Student(String aName) {
name = aName;
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com