java - Running Abstract Methods from other classes -


im working on project , ease of use wanted able create class extending "screen" interface , screen class initialised main method -

//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 doesn't work because cant instantiate abstract class. have tried

screen.init(); 

but cant call method unless static. how can i'm trying achieve? if not clear enough please ask in comments don't flag , update question.

edit: know can instantiate game class not point of this. trying run init method in every class implementing screen interface dont have specify each 1 induvidually.

why not

game s = new game (); s.init (); 

or if have use screen interface then

screen s = new game (); s.init (); 

also seem confused between interfaces , abstract classes.. defining interface. not extend interfaces , can not instantiate interface

if want init called automatically suggest add static block or call super constructor


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -