# Refering to a class rather than an object for collision

**URL:** <https://discourse.processing.org/t/refering-to-a-class-rather-than-an-object-for-collision/23933>\
**Category:** Coding Questions\
**Created:** [September 18, 2020, 9:37am UTC](https://discourse.processing.org/t/refering-to-a-class-rather-than-an-object-for-collision/23933 "2020-09-18T09:37:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan999](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@Dan999](https://discourse.processing.org/u/Dan999)\
**Post date:** [September 18, 2020, 9:37am UTC](https://discourse.processing.org/t/refering-to-a-class-rather-than-an-object-for-collision/23933/1 "2020-09-18T09:37:05Z")

</div>

I want to refer to a class rather than an object, so I don’t need a seperate if statement for each object, does anybody know how to do this?

---

<div class="post-metadata">

**Author:** ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)\
**Post date:** [September 18, 2020, 10:06am UTC](https://discourse.processing.org/t/refering-to-a-class-rather-than-an-object-for-collision/23933/2 "2020-09-18T10:06:54Z")

</div>

maybe you could give us some example code. not sure what you mean with the ‘if statement’ part.

if you have many instances of a class, you may give each one a very unique name - then you would have to remember all those names.  
or - usually - you would create an array of the objects and address them through a for-loop.

that way each instance would have its own random number anyway…

```auto
myClass [] xy;

void setup() {
  xy = new myClass[100];
  for (int i=0; i<100; i++) {
    xy[i] = new myClass();
  }
}
//-----------------------
class myClass {
  float r;
  //-----------------------
  myClass () {
    findRandom ();
  }
  //-----------------------
  void findRandom () {
    r = random (0,789);
    print (r);
  }
}

```
