Note that there are some explanatory texts on larger screens.

plurals
  1. POChild class method not overriding the method of the same signature in parent
    primarykey
    data
    text
    <p>Why is my child class method not overriding the method of the same signature in its parent class?</p> <h2>Summary:</h2> <p>I have a class <code>PlayerPaddle</code> that extends an abstract class <code>Paddle</code>, which extends the abstract class Actor (the context here is a pong game). <code>Paddle</code> and <code>PlayerPaddle</code> both have a method with the same signature: </p> <pre><code>public void moveDown() </code></pre> <p>The intention is to have the <code>PlayerPaddle</code> <code>moveDown</code> method override that of <code>Paddle</code>. The problem here is when I call <code>this.moveDown()</code> inside <code>PlayerPaddle</code>, only the <code>moveDown</code> method of <code>Paddle</code> is called. </p> <h2>The details:</h2> <p>Breakpoints set on <code>moveDown()</code> in <code>Paddle</code> are tripped, while breakpoints on <code>moveDown()</code> in <code>PlayerPaddle</code> never trip. I also tried <code>@Override</code> on the <code>PlayerPaddle</code> <code>moveDown</code> method, but it still calls the <code>Paddle</code> <code>moveDown</code> method. </p> <h2>The context:</h2> <p>The goal is for <code>PlayerPaddle</code> objects to move up/down at a different speed than other <code>Paddle</code> objects. So the same problem occurs for the <code>moveUp</code> method as well.</p> <h2>Code below:</h2> <pre><code>abstract public class Actor { public void releasedEvent(KeyEvent e) { } } abstract public class Paddle extends Actor { public void moveDown() { // this method is called body.setVel(0, Game.dX / 10.); } } public class PlayerPaddle extends Paddle { @Override public void moveDown() { // this method never gets called body.setVel(0, Game.dX ); } public void receiveEvent(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_UP) { this.moveUp(); } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { this.moveDown(); // Want to call moveDown() inside PlayerPaddle } } } </code></pre> <p>I am happy to provide clarification.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload