title: Calling a Method if another Method is called
body: <p>I'm feeling curious. In Java, is it possible to nest a newly created method inside of a method? I ask this because in my book there are these practice exercises for each section (I'm currently on Objects/Classes) and there's a question that tells you to call a boolean method as true if another method - in the same class - was called (in the class that was called the boolean variable becomes true). Here's an example:</p>
  
  <pre><code>public void setTrue(int someRandomStuff) {
     this.someRandomStuff  = superRandomStuff; 
     // this is where the boolean variable comes into play
     trueOrFalse = true;
  }
  </code></pre>
  
  <p>Now I was wondering is it possible to put another method inside of this method that calls if the method setTrue sets 'trueOrFalse' to true? Or would I have to create another method entirely? I'm only trying it this way because I haven't really read anything that said this wasn't possible. I've tried it like this and IntelliJ doesn't really show if it's wrong, so I'm gonna assume it must be possible.</p>
  
  <p>Here's what I've tried for further clarification on what I mean:</p>
  
  <pre><code>public void setTrue(int someRandomStuff) {
     this.someRandomStuff = superRandomStuff;
     trueOrFalse = true;
     if (trueOrFalse) { 
       public boolean getTrueOrFalse() {
       return true;
     }
  }
  </code></pre>
  
  <p>I'm honestly trying to learn why and how things work the way they do, rather than just do it because someone/something tells me that's the way it is and always will be.</p>
  
  <p>If you're curious about the formatting or want exercises similar to this the book is called: <a href="https://rads.stackoverflow.com/amzn/click/com/0132936526" rel="nofollow noreferrer" rel="nofollow noreferrer">Introduction to Java, Comprehensive Version (9th Edition).</a></p>