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. Note the peculiar use of the square brackets instead of parentheses: no constructor is being called! | + | * '''Ring[] elvenRing = new Ring[3]; ''' creates an array of three Ring ***VARIABLES***. It does not create any Ring instances for those variables to point to. Note the peculiar use of the square brackets instead of parentheses: no constructor is being called! |
* Ring.forged() shows that we have not created any new 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. | * 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. |