In the following example, the variable b
is declared final
, but not static
. That means it's a constant instance variable. However, because it's constant, none of the Passenger
objects can change its value. So isn't it better to declare it static
and make it a class variable, so that there is only one copy to be used by all instantiated objects?
class Passenger {
int a;
final int b = 0;
void drive() {
System.out.println("I'm driving!");
}
}