Originally Posted by playn1990
Man.., well i did say beginner question.. ARGH...
p[n] = new Person();
thx for the help ...
You betcha, that was far more valuable than I telling you what the problem wasn't it
To actually answer the problem in detail - a creation of a
array is simply telling it that the assigned variable will be 5 * sizeof(Object) in size. It doesn't yet have any data within it. This is the same with a standard definition of a variable:
, where we know that 'p' is reserved for a 'Person', but we don't yet have a person in there. The call to the
is what creates an actual object;
differs in that it is not instantiating the object, just allocating for it.
More often than not this is what you well see is the cause of a NullPointerException. When you try to access a property or method of an un-instantiated object. We know that the object is referenced by the variable, but we don't know when it gets there (could be manipulated externally from a different class). This is why a compiler isn't to choke on this error, and you get a runtime exception instead.