title: Can we call a function within a function in Java?
body: <p>If we declare a method to be static, then without needing to instantiate we can call that method anywhere within the class body.</p>
  
  <p>If we do not declare a method to be static, then an object can be instantiated and we call the method.</p>
  
  <p>Now if we do not declare a method to be static and also do not instantiate, can we call a function within a function?</p>
  
  <p>EDIT:</p>
  
  <p>I understand now, that my hunch was right. We cannot call another function within a function unless there static or object instantiation.</p>
  
  <p>But in Java applets I remember seeing a function being called from another function. </p>
  
  <pre><code>import javax.swing.*;
  import java.awt.Container;
  
  public class MethodCall extends JApplet
  {
      public void init()
      {
          String output = "";
          JTextArea outputarea=new JTextArea(10,20);
          Container c = getContentPane();
          c.add(outputarea);
  
          int result;
          for(int x=1;x&lt;=10;x++)
          {
              result = square(x);
              output += "Square of " + x + " is " + result + "\n";
          }//end of for loop
  
          outputarea.setText(output);
      }//end of init()
  
      public int square(int y)
      {
          return y*y;
      }//end of square()
  
  }//end of class MethodCall
  </code></pre>
  
  <p>See square() function</p>