Forging The Rings!
From Huben's Wiki
Line 63: | Line 63: | ||
* The oneRing instance is created by calling the constructor and setting the constructor argument theMetal to "gold" and whom to "Sauron". | * The oneRing instance is created by calling the constructor and setting the constructor argument theMetal to "gold" and whom to "Sauron". | ||
* Now when we call Ring.forged(), it shows that 1 ring has been forged. | * Now when we call Ring.forged(), it shows that 1 ring has been forged. | ||
+ | * '''Ring[] elvenRing = new Ring[3]; ''' creates an array of three Ring ***VARIABLES***. It does not create any Ring instances. | ||
+ | * Ring.forged() shows that we have not created any new instances. | ||
+ | * So what is in those three Ring variables, if they are not pointing to Ring instances? The value '''null'''. When we try to println one of the Ring variables, elvenRing[0], the result is a null. | ||
+ | * We laboriously create three Ring instances and assign them to each Ring variable in the array. |