Given the Java class City.
What is the point of writing City springfield = new City();
Instead of springfield = new City();
Given the Java class City.
What is the point of writing City springfield = new City();
Instead of springfield = new City();
There is no point, since Java 10, for local variables. For local variables you can instead write:
var springfield = new City();
Also, you can create an object without introducing an object reference, if you create an object in an expression. Typically this is done in a method call:
settlements.add(new City());
You must still repeat the class name for attributes (fields).
But, there is an exception to this. If you want to program to an interface, you must indicate the type of object you are constructing and the interface class you want the object reference to have:
Settlement springfield = new City();