I have abstract class Tester, with abstract method test() and main method:
abstract class Tester {
abstract String test();
public static void main(String[] args) {
doSomething();
Tester t = new Tester() {
@Override
String test() {
return "";
}
};
result = t.test();
doSomethingElse();
}
}
Obviously t.test() will always return "" for this class and any other subclasses.
But I want to call method test() inside of main method, that way that any subclass will have its own test method called at its execution (in its inherited main method).
Is that even possible in way I imagined ? Can I somehow declare object t as a subclass object (without knowing his name) so he can use his own implementation of this abstract method ?