Answer the question
In order to leave comments, you need to log in
How to make a method in java execute only on call?
I am new to Java and have a question. Is it technically possible to implement a method that will not be executed until it is called by another method.
Roughly speaking, the code is something like this. I need the restart() method to be executed only when the run() method calls it, provided that the value of Running == false. However, the method is executed when the program starts, until the conditions I need are met.
class Game{
private boolean running = true;
public void run() {
while (running) {
тут какие то методы которые выполняются и не мешают
}
while (!running){
restart();
}
}
public boolean restart() {
running = true;
return true;
}
}
Answer the question
In order to leave comments, you need to log in
The method cannot be executed by itself if you have, for example, two methods in the listing, one as the entry point to the program will be launched at startup, the second and others only if you call it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question