I'm also getting a runtime null pointer exception with this version when MyClass.set(int) is called, and I suspect it has to do with the creation of the array elements.public class Main {public class Main { public static void main(String[] args){ // class class MyClass{ int x; public int get(){ return this.x; }; public void set(int newX){ this.x = newX; } } // create array MyClass[] mcArray = new MyClass[10]; System.out.println(String.format("array is %s elements long", mcArray.length)); // attempt to set array elements for(MyClass thisOne : mcArray){ thisOne.set(2); } } // main } // Main