A
A
Alexander Fedoseev2018-11-17 14:55:45
Java
Alexander Fedoseev, 2018-11-17 14:55:45

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

1 answer(s)
V
Vadim Popov, 2018-11-19
@WarmLampGuy

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 question

Ask a Question

731 491 924 answers to any question