I am new to Java. I am reading a toy code, and notice all the other methods expect "start" and "stop" methods are static. And due to this "stop" can only be called as via ".this.stop()" (The "here" line). What's the advantage implement like this, why not make "start" and "stop" also static methods?
public class MyService {
private MyService() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
MyService.this.stop(); <----- here
} catch (IOException | InterruptedException e) {
...
}
}
});
}
protected void stop() {
....
}
protected void start() {
....
}
public static xxx getXXX() {
return xxx;
}
....
}