# Nomenclature question for finding information about combining classes

**URL:** https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919
**Category:** Beginners
**Created:** [September 21, 2022, 6:17pm UTC](https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919 "2022-09-21T18:17:10Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [September 21, 2022, 6:17pm UTC](https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919/1 "2022-09-21T18:17:10Z")

</div>

Hello!!  
Is this called **nested classes**?

I need to know the correct name for placing a class within a class so I can search for reference materials.

For example, if I have 3 separate classes:  
1st one = Grid class  
2nd one = Shape class  
3rd one = Color class

I want to find info on how to access the Shape class in the Grid class, etc

Thank you in advance!  
🤓

---

<div class="post-metadata">

### Author: ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)
#### Post date: [September 21, 2022, 6:25pm UTC](https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919/2 "2022-09-21T18:25:51Z")

</div>

It is called inner classes as far as I know.

Inner classes can’t have static elements and each instance is bound to a enclosing instance.  
Processing handles it’s classes that way.

So if you create a new class in Processing it in reality creates a inner class of the sketches class.

Each element of a inner class can access the fields and methods of it’s enclosing instance. And vice versa.

Here is a little example:

```auto
class A {
  A() {
  }
  B createNewInstance() {
    return new B();
  }
  class B {
    private int somePrivateField=0;
    B() {
    }
    A getEnclosingInstance() {
      Object ret=null;
      try {
        java.lang.reflect.Field f=this.getClass().getDeclaredField("this$1");
        f.setAccessible(true);
        ret=f.get(this);
      }
      catch(Exception e) {
      }
      return (A) ret;
    }
  }
}
void setup() {
  A enclosingInstance=new A();
  A.B innerInstance=enclosingInstance.new B();
  println(innerInstance.somePrivateField);
  println(enclosingInstance,innerInstance.getEnclosingInstance());
}

```

---

<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: [September 21, 2022, 7:36pm UTC](https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919/3 "2022-09-21T19:36:17Z")

</div>

you can also just write the 3 classes one after another separately:

```auto
class GridClass {
}

class ShapeClass {
}

class ColorClass {
}

```

and still have one class use the other; for example:

```auto
class GridClass {

    ArrayList<ShapeClass> list = ArrayList(); 
   
    void display(); 
        for(ShapeClass shape1 : list) {
            shape1.display(); 
        }
    }
}

class ShapeClass {

    ColorClass col = new ColorClass(); 
  
    void display() {
       fill(col.fillColor); 
    }

}

class ColorClass {
    color fillColor = color(222); 
    color strokeColor = color(111); 

}

```

etc.

---

<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: [September 21, 2022, 7:40pm UTC](https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919/4 "2022-09-21T19:40:12Z")

</div>

> [@NumericPrime](#):
>
> Inner classes can’t have `static` elements…

Actually there’s a notable exception to that rule: 📏

> [@Using class-wide methods in non-static classes](https://discourse.processing.org/t/using-class-wide-methods-in-non-static-classes/1677/4):
>
> Nice step-by-step @kfrajer. However, we can exceptionally have static fields inside inner classes as long as they’re final & either primitive or String; b/c in this case, they become compile-time constants: grinning void setup() { final AutoCar car = new AutoCar(); println("Planet:", car); // Planet: MARS exit(); } class AutoCar { static final String PLANET = "MARS"; // Compile-time constant @Override String toString() { return PLANET; } }

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [September 22, 2022, 12:08am UTC](https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919/5 "2022-09-22T00:08:23Z")

</div>

Hello @NumericPrime  
Yes, I was wondering about inner classes. Though this looks a bit more complex than I had envisioned…  
🫢  
But I definitely appreciate seeing this example for future use when I’m further along in my coding knowledge.  
Thank you!!  
🤓

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [September 22, 2022, 12:13am UTC](https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919/6 "2022-09-22T00:13:10Z")

</div>

@Chrisir !!  
This makes sense. I think this is the direction I want to go.  
Thank you!!  
🤓

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [September 22, 2022, 4:01am UTC](https://discourse.processing.org/t/nomenclature-question-for-finding-information-about-combining-classes/38919/7 "2022-09-22T04:01:21Z")

</div>

It took a little while but I finally got this to work!! Thank you again!!!  
🤓

 ![Screen Shot 2022-09-21 at 11.54.25 PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/e/1e823f0c7612ca4f9b2ce1a5e8356ae0493f1662.png)
