final methods

Figure 435. Moving Shape instances Slide presentation Create comment in forum

Figure 436. Implementing Shape movements Slide presentation Create comment in forum
public class Shape {
  /**
   * Move by a given translation vector
   * @param xTrans Translation's x component
   * @param yTrans Translation's y component
   */
  public void move(final int xTrans, final int yTrans) {
    x += xTrans;
    y += yTrans;
  } ...

Figure 437. Fools are everywhere! Slide presentation Create comment in forum
public class Rectangle extends Shape {
  @Override public void move(int xTrans, int yTrans) {
    // I'm so dumb!
    ...
  }

Figure 438. Solution: final prevents overriding Slide presentation Create comment in forum
public abstract class Shape {
... public final void move(final int xTrans, final int yTrans) {
      x += xTrans;
      y += yTrans;
    }...
public class Rectangle extends Shape {
  // Syntax error: 'move(int, int)' cannot override
  // 'move(int, int)' in 'inherit.Shape'; overridden method is final
  @Override public void move(int xTrans, int yTrans) {...