In
Java "Bar aBar;" declares a reference to an object that must be an instance of Bar. (This is different than in C++.) To create a Bar object and have aBar refer to it, you must do something like "aBar = new Bar();".
The same applies to arrays. Each element of an "array of objects" really holds a reference to such an object. But it is a null reference until you create such an object and assign it to the array element. So try somethink like:
public static void main(String[] args)
{
for (int i=0; i < mybar.length; ++i) mybar[i] = new bar();
mybar[2].setcoords(2,2); // no longer GIVES NULL POINTER ERROR
}
Not that this situation is different for primative types, like int or float.