public enum Apple { PIPO(1), BIBO(2), GITO(3); private int price; Apple(int price){ this.price = price; } int getPrice(){ return price; } } public class Test { public static void main(String[] args) { Apple apple1 = Apple.PIPO(2); System.out.println(apple1); } }
Apple has a defined constructor in enum and I don’t understand why we write the enumeration data to the constructor right in ENUM, and not in another place when creating the object, let's say we do it with classes:
PIPO(1), BIBO(2) ... // в enum(e), а не вот ниже public class Test { public static void main(String[] args) { Apple apple1 = Apple.PIPO(2); //вот тут System.out.println(apple1); } }