Bargains With Evil
From Huben's Wiki
(→Read The Contract Carefully!) |
|||
Line 40: | Line 40: | ||
== Read The Contract Carefully!== | == Read The Contract Carefully!== | ||
− | The first thing we must understand in these code examples is the idea of '''local variables'''. Local variables are declared within | + | The first thing we must understand in these code examples is the idea of '''local variables'''. Local variables are declared within methods. Local variables can ONLY be used inside their own methods, and actually only within their own block and any inner blocks. This is a principle called '''scope'''. Arguments in method signatures are also local variables. |
+ | |||
+ | (The variables we have seen declared outside of methods are called ''fields''. Fields can be used in any method. If they are ''public'', then any method of any class can use them. If they are ''private'', then only methods of their own class can use them. Demons do have secrets to keep, after all.) | ||
A method call sets argument variables in the method. In the Innocent.main() call to Evil.bargain(), Evil.bargain()'s whatIsGiven argument is set to the String "honor". | A method call sets argument variables in the method. In the Innocent.main() call to Evil.bargain(), Evil.bargain()'s whatIsGiven argument is set to the String "honor". |