Forging The Rings!
From Huben's Wiki
(Created page with "Today we will study with [http://lotr.wikia.com/wiki/Rings_of_Power Celebrimbor, forger of the rings of power]. == The Ring Class == We must create a '''class Ring''' that has '...") |
|||
Line 26: | Line 26: | ||
</pre> | </pre> | ||
Constructors such as this one are methods with arguments. The arguments are variables. Their values are set when the constructor is called (right after a '''new''' keyword.) | Constructors such as this one are methods with arguments. The arguments are variables. Their values are set when the constructor is called (right after a '''new''' keyword.) | ||
+ | |||
+ | Setting the metal and givenTo fields with the values of the arguments is obvious. But the subtle thing is that the class variable numberForged, which started at zero, is now increased by one every time this constructor is called, which means for every ring instance created. We are counting the number of rings created! |