I have difficulties understanding how to correctly count a reference variables.
Example (adopted from some book for java learning):
class Car {
}
class Example {
public static void main(String[] args) {
a = new Car();
b = new Car();
Car[] cars = {a,a,a,a};
}
}
How many reference variables does class Car() have (variables referring to it)?
My answer is 2. There is only two variables "a" and "b" referring to object Car(). But correct answer is 6. Why are variables a counted as separate references inside the list? Isn't it same reference "a"?