# How to reference an object in another function to its class?

**URL:** <https://discourse.processing.org/t/how-to-reference-an-object-in-another-function-to-its-class/17964>\
**Category:** Beginners\
**Created:** [February 21, 2020, 3:39am UTC](https://discourse.processing.org/t/how-to-reference-an-object-in-another-function-to-its-class/17964 "2020-02-21T03:39:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon94203042](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@anon94203042](https://discourse.processing.org/u/anon94203042)\
**Post date:** [February 21, 2020, 3:39am UTC](https://discourse.processing.org/t/how-to-reference-an-object-in-another-function-to-its-class/17964/1 "2020-02-21T03:39:17Z")

</div>

Let’s say that we have a class and a function (sorry for the peudo-code):

```auto
class Person
{
    int age;
}

Person squid;

void IncreaseAge(Human object)
{

}

```

How would I make it so that I could do something like this:

```auto
void IncreaseAge(Human dataType)
{
    squid.age += 1;
}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2020, 5:43am UTC](https://discourse.processing.org/t/how-to-reference-an-object-in-another-function-to-its-class/17964/2 "2020-02-21T05:43:07Z")

</div>

1 way to do it: 👼

```auto
Person squid;

void setup() {
  frameRate(1);
  squid = new Person();
}

void draw() {
  squid.increaseAge(); // alt.: ++squid.age;
  print(squid);
}

class Person {
  int age;

  Person increaseAge() {
    ++age;
    return this;
  }

  String toString() {
    return "Age: " + age + TAB;
  }
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 21, 2020, 5:50am UTC](https://discourse.processing.org/t/how-to-reference-an-object-in-another-function-to-its-class/17964/3 "2020-02-21T05:50:30Z")

</div>

Another more “functional” way, w/o a method: 😸

```auto
Person squid;

void setup() {
  frameRate(1);
  squid = new Person();
}

void draw() {
  increaseAge(squid); // alt.: ++squid.age;
  print(squid);
}

Person increaseAge(final Person human) {
  ++human.age;
  return human;
}

class Person {
  int age;

  String toString() {
    return "Age: " + age + TAB;
  }
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 21, 2020, 1:32pm UTC](https://discourse.processing.org/t/how-to-reference-an-object-in-another-function-to-its-class/17964/4 "2020-02-21T13:32:51Z")

</div>

Hello,

Processing:

> **[Object / Reference](https://processing.org/reference/object)**
>
> Objects are instances of classes. A class is a grouping of related methods (functions) and fields (variables and constants).

> **[Objects](https://processing.org/tutorials/objects/)**
>
> The basics of object-oriented programming.

> **[class / Reference](https://processing.org/reference/class.html)**
>
> Keyword used to indicate the declaration of a class. A class is a composite of fields (data) and methods (functions that are a part of the class) which may be instantiated as objects. The first lette…

[Coding Train 7.1: Introduction to Functions and Objects - Processing Tutorial](https://www.youtube.com/watch?v=XCu7JSkgl04)

Java:  
[[Lesson: Classes and Objects (The Java™ Tutorials \> Learning the Java Language)](https://docs.oracle.com/javase/tutorial/java/javaOO/index.html)]([http://The](http://The) Java Tutorials)

`:)`
