# Instantiate one class inside another using a third

**URL:** <https://discourse.processing.org/t/instantiate-one-class-inside-another-using-a-third/29414>\
**Category:** Coding Questions\
**Created:** [April 16, 2021, 4:27pm UTC](https://discourse.processing.org/t/instantiate-one-class-inside-another-using-a-third/29414 "2021-04-16T16:27:37Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [April 16, 2021, 5:06pm UTC](https://discourse.processing.org/t/instantiate-one-class-inside-another-using-a-third/29414/2 "2021-04-16T17:06:54Z")

</div>

You’re over-complicating this.

```auto
void setup() {
  size(200,200);
  A a = new A();
  a.hello();
}

void draw(){
  background(0);
}

class A {
  String s;
  B b;
  
  A() {
    C c = new C(this);
    c.snakes();
  }

  void hello() {
    println("hello from A!");
    b.hello();
    println(s);
  }
}

class B {
  B() {
  }

  void hello() {
    println("hello from B!");
  }
}

class C {
  A parent;
  C ( A in_a ) {
    parent = in_a;
    parent.b = new B();
  }
  void snakes(){
    parent.s = "Snakes! Argh!";
  }
}

```

Please don’t make me explain this…

---

_[View the full topic](https://discourse.processing.org/t/instantiate-one-class-inside-another-using-a-third/29414)._
