I study java. I got to the transfers, and then just the removal of the brain is going on. If I write something incorrectly (and then I write as I myself understood everything), then correct and explain, please.
enum Size { SMALL, MEDIUM, LARGE, EXTRA_LARGE; } In this line, the compiler created 4 instances of the Size class, which contain the names of enumeration constants and their sequence numbers using some Size class constructor, which is inherited from this superclass constructor:
protected Enum(String name, int ordinal); I cannot create somewhere else of the Size class instance, since There is no constructor with the appropriate access key. Suppose there is still more or less clear. I went further:
package main; enum Size { SMALL(10), MEDIUM(20), LARGE(30), EXTRA_LARGE(40); private int size; Size(int size) { //super("Name", 1); this.size = size; } int getSize() { return size; } } public class Main { public static void main(String... args) { Size size = Size.SMALL; //Size size1 = new Size(3); } } Then it is not clear: Why the compiler does not skip super ("Name", 1) in the constructor of the Size class. After all, the constructor I invoke in the Enum superclass is declared as protected. In addition, it is not the default constructor and it is the only one in the Enum superclass. Those. I MUST call him explicitly !!!
And it is not clear:
The compiler does not skip Size size1 = new Size (3), although I am in the same package!