# Reference subclass method in superclass method

**URL:** <https://discourse.processing.org/t/reference-subclass-method-in-superclass-method/40662>\
**Category:** Coding Questions\
**Created:** [January 20, 2023, 5:36pm UTC](https://discourse.processing.org/t/reference-subclass-method-in-superclass-method/40662 "2023-01-20T17:36:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanto2016](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nanto2016](https://discourse.processing.org/u/nanto2016)\
**Post date:** [January 20, 2023, 5:36pm UTC](https://discourse.processing.org/t/reference-subclass-method-in-superclass-method/40662/1 "2023-01-20T17:36:05Z")

</div>

I have a Saw class that extends the Enemy class.

```auto
class Enemy {
  int hp, atk, n;
  float spd;
  PVector pos = new PVector(random(width), random(height));
  Enemy(int hp_, float spd_, int atk_, int n_) {
    hp = hp_;
    spd = spd_;
    atk = atk_;
    n = n_;
  }
  
  void update() {
    PVector target = new PVector(vac.x, vac.y);
    target.sub(pos);
    target.setMag(spd);
    pos.add(target);
    subUpdate();
  }
  
  void display() {
    image(enemy[n], pos.x, pos.y);
  }
}

class Saw extends Enemy {
  Saw() {
    super(5, 4.0, 10, 0);
  }
  
  void subUpdate() {
    
  }
}

```

In `update()` I want to call the `subUpdate()` method from the Saw class. Is this possible? I really can’t find any solution.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [January 20, 2023, 6:00pm UTC](https://discourse.processing.org/t/reference-subclass-method-in-superclass-method/40662/2 "2023-01-20T18:00:51Z")

</div>

Hi @nanto2016,

No! But you can call super.update() on your subclass.  
So just call subUpdate on your Saw object (would rename it to update though) and inside call super.update(). That is imo what you want.

You need to think on it a bit different…

Cheers  
— mnse
