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:
public void setTrue(int someRandomStuff) {
this.someRandomStuff = superRandomStuff;
// this is where the boolean variable comes into play
trueOrFalse = true;
}
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.
Here's what I've tried for further clarification on what I mean:
public void setTrue(int someRandomStuff) {
this.someRandomStuff = superRandomStuff;
trueOrFalse = true;
if (trueOrFalse) {
public boolean getTrueOrFalse() {
return true;
}
}
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.
If you're curious about the formatting or want exercises similar to this the book is called: Introduction to Java, Comprehensive Version (9th Edition).