How to deal with designers?

Started to learn Java, reached the designers and hovered. I can not understand why here

CatBox Box = new Box();

we twice write the Box?

Which means the first and second, and then use the variable catBox?

I would be grateful for the available examples.
July 9th 19 at 10:04
3 answers
July 9th 19 at 10:06
Your line is declaring a variable and assigning it a value. Because in Java there is no auto type inference, you must specify the type of each variable.
Let's say Box aBox; you declared a variable of type Box with the name of the aBox. Now you can assign it a value just like Box(an instance of the Box class, an implementation of the interface Box, or an heir of class Box).
And on the right the actual creation of the instance of the Box class using the constructor
July 9th 19 at 10:08
1) Box catBox; // declare a variable with type Box and the name of the catBox (just announced there's nothing in it)
2) new Box(); // create a new object of type Box (and threw)
3) catBox = new Box(); // create a new object of type Box and said that it is possible to communicate using 3) variable catBox
4) Box catBox = new Box(); // declare a variable and immediately it connected the object
July 9th 19 at 10:10
The first Box is the type of the declared variable.
The second Box creates instant class, via a call to the default constructor.

Find more questions by tags Java