so let's say i have a class called city. what's the difference from where i initialize its fields? e.g.
public class City {
private String cityName;
private int population;
private boolean goodPeopleLiveThere;
City() {
cityName = "las vegas";
population = 603488;
goodPeopleLiveThere = true;
}
}
why would i initialize in the constructor rather than the fields or vice versa?
see the ambiguity i face is typically i would set them as parameters in the constructor and then initialize them in the main() when i instantiate my class, but then some tutorials i've seen used initialized them like aforementioned, and i'm yet to fully understand the implications of initialize in fields/constructor rather than in the object.