点赞关注,不会迷路!
文末领取最新学习面试资料
程序员经常会遇到灵魂拷问:你有对象吗?
没有,但我可以 new 一个!
-
public class GirlFriend {
-
private String name;
-
private int age;
-
// 省略 getter & setter ...
-
public static void main(String[] args) {
-
GirlFriend myGirlFriend = new GirlFriend();
-
myGirlFriend.setName("小美");
-
myGirlFriend.setAge(18);
-
}
-
}
没问题,老铁!但如果对象的属性太多,咋办?
-
public class GirlFriend {
-
private String name;
-
private int age;
-
private int bust;
-
private int waist;
-
private int hips;
-
private List<String> hobby;
-
private String birthday;
-
private String address;
-
private String mobile;
-
private String email;
-
private String hairColor;
-
private Map<String, String> gift;
-
// 等等等等 ...
-
// 省略 getter & setter ...
-
public static void main(String[] args) {
-
GirlFriend myGirlFriend = new GirlFriend();
-
myGirlFriend.setName("小美");
-
myGirlFriend.setAge(18);
-
myGirlFriend.setBust(33);
-
myGirlFriend.setWaist(23);
-
myGirlFriend.setHips(33);
-
myGirlFriend.setBirthday("2001-10-26");
-
myGirlFriend.setAddress("上海浦东");
-
myG