# Illegal modifier for the local class player; only abstract or final is permitted

**URL:** <https://discourse.processing.org/t/illegal-modifier-for-the-local-class-player-only-abstract-or-final-is-permitted/40970>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [February 21, 2023, 12:07am UTC](https://discourse.processing.org/t/illegal-modifier-for-the-local-class-player-only-abstract-or-final-is-permitted/40970 "2023-02-21T00:07:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shoux2](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@shoux2](https://discourse.processing.org/u/shoux2)\
**Post date:** [February 21, 2023, 12:07am UTC](https://discourse.processing.org/t/illegal-modifier-for-the-local-class-player-only-abstract-or-final-is-permitted/40970/1 "2023-02-21T00:07:13Z")

</div>

```auto

void player() {
  public class player {
    private int dx;
    private int dy;
    private int x = 40;
    private int y = 60;
    private int w;
    private int h;
    private Image image;

    public player() {
      loadImage();
    }

    private void loadImage() {
      ImageIcon ii = new ImageIcon("player.png");
      image = ii.getImage();

      w = image.getWidth(null);
      h = image.getHeight(null);
    }

    public void move() {
      x += dx;
      y += dy;
    }

    public int getX() {
      return x;
    }

    public int getY() {
      return y;
    }

    public int getWidth() {
      return w;
    }

    public int getHeight() {
      return h;
    }

    public Image getImage() {
      return image;
    }

    public void keyPressed(KeyEvent e) {
      int key = e.getKeyCode();
      if (key == KeyEvent.VK_LEFT) {
        dx = -2;
      }

      if (key == KeyEvent.VK_RIGHT) {
        dx = 2;
      }

      if (key == KeyEvent.VK_UP) {
        dy = -2;
      }

      if (key == KeyEvent.VK_DOWN) {
        dy = 2;
      }
    }

    public void keyReleased(KeyEvent e) {
      int key = e.getKeyCode();

      if (key == KeyEvent.VK_LEFT) {
        dx = 0;
      }

      if (key == KeyEvent.VK_RIGHT) {
        dx = 0;
      }

      if (key == KeyEvent.VK_UP) {
        dy = 0;
      }

      if (key == KeyEvent.VK_DOWN) {
        dy = 0;
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 21, 2023, 1:57am UTC](https://discourse.processing.org/t/illegal-modifier-for-the-local-class-player-only-abstract-or-final-is-permitted/40970/2 "2023-02-21T01:57:02Z")

</div>

The class must not be inside a function

---

<div class="post-metadata">

**Author:** ![shoux2](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@shoux2](https://discourse.processing.org/u/shoux2)\
**Post date:** [February 21, 2023, 2:09am UTC](https://discourse.processing.org/t/illegal-modifier-for-the-local-class-player-only-abstract-or-final-is-permitted/40970/3 "2023-02-21T02:09:28Z")

</div>

Tysm so you have to delete `void player() {}` right?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 21, 2023, 6:12am UTC](https://discourse.processing.org/t/illegal-modifier-for-the-local-class-player-only-abstract-or-final-is-permitted/40970/4 "2023-02-21T06:12:01Z")

</div>

Yes. Or close this function before the class starts. Use `}` bracket

There is a nice text tutorial about objects and classes

**Remarks**

You also need `setup()` and `draw()` outside of the class.

Are you working in the processing IDE?

Data type is PImage, not Image.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 21, 2023, 10:22am UTC](https://discourse.processing.org/t/illegal-modifier-for-the-local-class-player-only-abstract-or-final-is-permitted/40970/5 "2023-02-21T10:22:32Z")

</div>

> [@Chrisir](#):
>
> Data type is PImage, not Image

The data type is `Image` because the Image is obtained fron Java AWT or Swing

Couple of other points regarding the original code

In Java it is normal to capitalise the class name so use `Player` , this helps others to identify your user defined classes.

Generally I would avoid using Processing function/variable names in your class. `loadImage` is a Processing function that loads a bitmap file into a `PImage` object hence the confusion you caused for @Chrisir
