Such a condition of the problem. The options that I know do not meet this condition:
one)
MyClass[] classes = new MyClass[]{new N1(), new N2() ...}; 2)
A n1 = new A(...); B n2 = new B(...); MyClass[] classes = new MyClass[]{n1, n2 ...}; 3)
ArrayList<MyClass> list = new ArrayList<>(); A n1 = new A(...); B n2 = new B(...); .... Collections.addAll(list, n1, n2 ...); } In example # 1, operators are used to create objects during array initialization. In Example 2, the objects are initialized separately, and when the array is initialized, we add references to these objects to it, which also does not quite match the condition, similarly to Example No. 3.
Maybe there are more options, and you can still use only one operator to declare and initialize an array? Or I misunderstand this condition of the problem. Tell me please!
Here is the exact text of the condition:
Using one operator, define and initialize an array of at least 20 purchases