# Creating an object from a class

**URL:** https://discourse.processing.org/t/creating-an-object-from-a-class/17296
**Category:** Beginners
**Created:** [January 23, 2020, 9:28pm UTC](https://discourse.processing.org/t/creating-an-object-from-a-class/17296 "2020-01-23T21:28:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![floflopm](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@floflopm](https://discourse.processing.org/u/floflopm)
#### Post date: [January 23, 2020, 9:28pm UTC](https://discourse.processing.org/t/creating-an-object-from-a-class/17296/1 "2020-01-23T21:28:20Z")

</div>

hi,

I would like to use the mousePressed function to create new objects from a class at the location of the mouse. But the class itself seems complicated (I’m working on an example I found). When I type:

```auto
void mousePressed(){
 Atom w = new Atom();
}

```

I get the message ‘‘The constructor HC.Atom() is undefined’’

Here’s the class:

```auto
class Atom 
{
  public PVector position,velocity,acceleration;
  public int type;
  public Atom(int t){
    position = new PVector(random(width),random(height));
    velocity = new PVector(random(-3,3),random(-3,3));
    acceleration = new PVector();
    type = t;
  }
  
  public void drawAtom()
  {
    switch(type) {
      case WATER: fill(color(0)); break; //Water color
      case HYDROPHOBIC: fill(color(255)); break; //oil color
      default: fill(color(255)); break;
    }
    ellipse(position.x,position.y,max(4,R),max(4,R)); // change shape
  }
  
}

```

---

<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: [January 23, 2020, 10:28pm UTC](https://discourse.processing.org/t/creating-an-object-from-a-class/17296/2 "2020-01-23T22:28:48Z")

</div>

The constructor requires one parameter

You have to pass a number to it inside ()

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [January 23, 2020, 11:27pm UTC](https://discourse.processing.org/t/creating-an-object-from-a-class/17296/3 "2020-01-23T23:27:30Z")

</div>

…and that constructor is here:

> [@floflopm](#):
>
> public Atom(int t){

So you either need to create an additional constructor `public Atom() {` which takes no arguments or you need to call like thiis: `Atom w = new Atom(10);`
