Im working on a project and for ease of use I wanted to be able to create a class extending my "Screen" interface and the screen class then be initialised from my main method like this -
//Screen Interface
public abstract interface Screen {
public abstract void init();
}
//Screen Implementation
public class Game implements Screen {
@Override
public void init() {
//Do stuff
}
}
//Main class
public class Main {
public static void main(String[] args) {
Screen s = new Screen();
s.init();
}
}
But this doesn't work because you cant instantiate an abstract class. I would have tried
Screen.init();
But you cant call a method like this unless its static. How can I do what i'm trying to achieve? If I was not clear enough please ask in the comments don't just flag and I will update my question.
EDIT: I know I can instantiate the Game class but that is not the point of this. I am trying to run the init method in every class implementing the Screen Interface so I dont have to specify each one induvidually.