I'm confused about this. Here is what I mean:
public class minMax {
private int min = Integer.MAX_VALUE;
public void changeMin() {
min = 10;
}
public static void main (String args[]) {
minMax ob1 = new minMax();
ob1.changeMin();
System.out.println(ob1.min); // outputs 10 <<<<
}
}
So it outputs 10, even thought we didn't explicitly bind a min
variable to the minMax
constructor. I thought that you would have to have a constructor that initializes the object using the variable for this to work. e.g.:
private int min;
public minMax() {
min = Integer.MAX_VALUE;
}
What am I missing? Would appreciate some explanation, thank you!
EDIT:
To Illustrate my point further, why would we ever need to do the following:
private int min;
public minMax() {
min = Integer.MAX_VALUE;
}
rather than leave it be the default constructor and just:
private int min = Integer.MAX_VALUE;
public minMax() {
}