title: abstract class which calls a method of a subclass. How does it work?
body: <p>I read a code which is written in the book "Beginning Android Games" but I don't understand it completly. The entry point of the app is:</p>
  
  <pre><code>public class MrNomGame extends AndroidGame {
      public Screen getStartScreen() {
          return new LoadingScreen(this); 
      }
  }
  </code></pre>
  
  <p>The class 'AndroidGame' which is extending here:</p>
  
  <pre><code>public abstract class AndroidGame extends Activity implements Game {
      AndroidFastRenderView renderView;
      Graphics graphics;
      Audio audio;
      Input input;
      FileIO fileIO;
      Screen screen;
      WakeLock wakeLock;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
          boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
          int frameBufferWidth = isLandscape ? 480 : 320;
          int frameBufferHeight = isLandscape ? 320 : 480;
          Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
                  frameBufferHeight, Config.RGB_565);
  
          float scaleX = (float) frameBufferWidth
                  / getWindowManager().getDefaultDisplay().getWidth();
          float scaleY = (float) frameBufferHeight
                  / getWindowManager().getDefaultDisplay().getHeight();
  
          renderView = new AndroidFastRenderView(this, frameBuffer);
          graphics = new AndroidGraphics(getAssets(), frameBuffer);
          fileIO = new AndroidFileIO(this);
          audio = new AndroidAudio(this);
          input = new AndroidInput(this, renderView, scaleX, scaleY);
          screen = getStartScreen();
          setContentView(renderView);
  
          PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
          wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");
      }
  
      @Override
      public void onResume() {
          super.onResume();
          wakeLock.acquire();
          screen.resume();
          renderView.resume();
      }
  
      @Override
      public void onPause() {
          super.onPause();
          wakeLock.release();
          renderView.pause();
          screen.pause();
  
          if (isFinishing())
              screen.dispose();
      }
  
      public Input getInput() {
          return input;
      }
  
      public FileIO getFileIO() {
          return fileIO;
      }
  
      public Graphics getGraphics() {
          return graphics;
      }
  
      public Audio getAudio() {
          return audio;
      }
  
      public void setScreen(Screen screen) {
          if (screen == null)
              throw new IllegalArgumentException("Screen must not be null");
  
          this.screen.pause();
          this.screen.dispose();
          screen.resume();
          screen.update(0);
          this.screen = screen;
      }
  
      public Screen getCurrentScreen() {
          return screen;
      }
  }
  </code></pre>
  
  <p>You see the class extending 'Activity' by itself. That means that the app get into if you open the app on your mobile phone. In the onCreate method there is a method which is called 'getStartScreen()'. That is a method of the inferface 'Game' which is implemented. But the method 'getStartScreen()' isn't implemented in 'AndroidGame' therefore it is an abstract class. The method 'getStartScreen()' is implemented in 'MrNomGame' as you remember. As I have mentioned already the method 'getStartScreen()' is called in the onCreate method. That is the point which is confusing me. A superclass calls a method from its subclass. How does it works? And what happens if there were two subclasses which extending 'AndroidGame'? For example:</p>
  
  <pre><code>public class MrNomGame2 extends AndroidGame {
      public Screen getStartScreen() {
          return new LoadingScreen(this); 
      }
  } 
  </code></pre>
  
  <p>Which 'getStartScreen()' method will be called? That one from MrNomGame or that from MrNomGame2?</p>
  
  <p>At least the Game-interface:</p>
  
  <pre><code>public interface Game {
      public Input getInput();
  
      public FileIO getFileIO();
  
      public Graphics getGraphics();
  
      public Audio getAudio();
  
      public void setScreen(Screen screen);
  
      public Screen getCurrentScreen();
  
      public Screen getStartScreen();
  }
  </code></pre>
  
  <p>I know that is much code. I hope you can help me. Thank you very much.</p>
  
  <p>Peter </p>