Get class variables from another class

here

this shows that you can access a value from another class / object via println(a.num);

As I explained, the issue was outside this line.

Note that a is a global object and therefore known inside class Two




One a;

void setup() {
  a = new One();
}

void draw() {
  a.display();
}

// ====================================================

public class One {
  Two b;
  int num;

  One() {
    //constr
    num=9;
    println(num);
    b=new Two();
  }

  void display() {
    b.display();
  }
}//class

// ====================================================

class Two {
  Two() {
    //constr
  }

  void display() {
    println(a.num); // no error
  }
}//class
//
3 Likes