I want to make a test program that instead of specifying main
method explicitly, extends a class/abstract class and overrides a method that gets called by that superclass eg init
.
My attempt:
JavaApplication.java
public class JavaApplication {
public JavaApplication(){
this.init(null);
}
public JavaApplication(String[] args) {
this.init(args);
}
public void init(String[] args) {
/* override me */
}
public static void main(String[] args) {
new JavaApplication(args);
}
}
MyApp.java:
public class MyApp extends JavaApplication {
@Override
public void init(String[] args) {
System.out.println("Hello, World!");
}
}
The code compiles but my init method is not called(The string does not appear).
What is the proper way of formulating this behavior in Java?
Related Questions: