Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860
The Demons Command Each Other - Huben's Wiki

The Demons Command Each Other

From Huben's Wiki
Jump to: navigation, search
(Created page with "We have penetrated the mysteries of finding demon commands. Now we must seek to use those commands, and thus control our demons. ==First Call== <pre> public class DayTheEarthSto...")
 
Line 1: Line 1:
 
We have penetrated the mysteries of finding demon commands.  Now we must seek to use those commands, and thus control our demons.
 
We have penetrated the mysteries of finding demon commands.  Now we must seek to use those commands, and thus control our demons.
 
==First Call==
 
==First Call==
 +
Place this class into Dr.Java, save, compile and run it.
 
<pre>
 
<pre>
 
public class DayTheEarthStoodStill
 
public class DayTheEarthStoodStill
Line 9: Line 10:
 
   }
 
   }
  
   public void saveTheWorld()
+
   static public void saveTheWorld()
 
   {
 
   {
 
     System.out.println("Gort: Klaatu barada nicto!");
 
     System.out.println("Gort: Klaatu barada nicto!");
Line 20: Line 21:
 
* are followed by parentheses enclosing '''arguments'''
 
* are followed by parentheses enclosing '''arguments'''
 
* and then are followed by the '''blocks''' we call their '''bodies'''.
 
* and then are followed by the '''blocks''' we call their '''bodies'''.
 +
 +
The first method, main, instructs the demon to use the second method, saveTheWorld.  This is called a '''method call''',or call for short.
 +
 +
* Method calls look something like the method signatures.  How can you tell them apart?
 +
* What would happen if the main method had another call to saveTheWorld on another line?
 +
* Create another method, named saveThrice, that calls saveTheWorld three times. Change main to call saveThrice two times.  How many times is the world saved?  Why?
 +
 +
==Calling Between Classes==
 +
Use File/New to start a new Java class, place this code in it, save it and compile it.
 +
<pre>
 +
public class Nietzsche
 +
{
 +
  public void speak()
 +
  {
 +
    System.out.println("Thus spake Zarathustra!");
 +
  }
 +
}
 +
</pre>
 +
Change the main of DayTheEarthStoodStill to have this code:
 +
<pre>
 +
  static public void main(String[] args)
 +
  {
 +
    Nietzsche nietzsche = new Nietzsche();
 +
    saveTheWorld();
 +
    nietzsche.speak();
 +
  }
 +
</pre>
 +
Compile and run DayTheEarthStoodStill.
 +
 +
In order to use the method of class Nietzsche, we had to creat an '''instance''' of that class with the name nietzsche: we have created another demon!  It too will obey our commands if we call it by name.  We shall speak more anon of instances.
 +
 +
* Change main to alternate the two sayings twice.  You need not recreate nietzsche.
 +
* make a method named alternate which will say each saying once, and use it three times in main to get six sayings.

Revision as of 13:43, 17 September 2012

Personal tools
translate