# What does add() do?

**URL:** https://discourse.processing.org/t/what-does-add-do/19356
**Category:** Beginners
**Created:** [April 3, 2020, 1:49am UTC](https://discourse.processing.org/t/what-does-add-do/19356 "2020-04-03T01:49:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Cybernet](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cybernet](https://discourse.processing.org/u/Cybernet)
#### Post date: [April 3, 2020, 1:49am UTC](https://discourse.processing.org/t/what-does-add-do/19356/1 "2020-04-03T01:49:24Z")

</div>

So I have a code:

```auto
class Projectile extends PVector
{
  PVector velocity;
 
  Projectile(PVector loc, PVector vel)
  {
    super(loc.x, loc.y);
    velocity = vel;
  }
 
  void Display()
  {   
    add(velocity); // what does this do?
    
    fill(0, 0, 255);
    ellipse(x, y, 3, 3);
  }
}

```

I found this on a example I saw. It creates a bullet, and shoots it towards the mouse. The example didn’t explain the code, so I had to figure out what I does. But I’m stuck on this part. When it says `add(velocity)`, it confuses me. What are you adding velocity too?

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [April 3, 2020, 2:08am UTC](https://discourse.processing.org/t/what-does-add-do/19356/2 "2020-04-03T02:08:11Z")

</div>

Since this is inside the Class Projectile which extends from PVector, the line in questions is invoking the [add()](https://processing.org/reference/PVector.html) associated to PVector. This is a core concept in object oriented programming where your Projectile class is inheriting fields, functions defined in PVector.

In other words, you can think of that line as `this.add(velocity);` so it is adding velocity to the member variables x,y,z, associated to your instantiated Projectile _object_, variables inherited from the PVector class.

Kf

---

<div class="post-metadata">

### Author: ![Cybernet](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cybernet](https://discourse.processing.org/u/Cybernet)
#### Post date: [April 3, 2020, 2:33am UTC](https://discourse.processing.org/t/what-does-add-do/19356/3 "2020-04-03T02:33:09Z")

</div>

Okay. Thank you. One more question too. Is it also the same idea with `ellipse(x, y, 3, 3)`? So the x and y are from PVector?

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [April 3, 2020, 3:04am UTC](https://discourse.processing.org/t/what-does-add-do/19356/4 "2020-04-03T03:04:07Z")

</div>

That is correct. You can see this in the docs and it the actual code:

- [https://processing.github.io/processing-javadocs/core/processing/core/PVector.html](https://processing.github.io/processing-javadocs/core/processing/core/PVector.html)
- [https://github.com/processing/processing/blob/master/core/src/processing/core/PVector.java](https://github.com/processing/processing/blob/master/core/src/processing/core/PVector.java)

Kf
