Ask coding questions

← Back to all posts
How would I make this work?

I want to create a new class to store variables & recall them but it doesn't work, is there a way to fix this or should I try a different way? Thanks!

Answered by SixBeeps (5223) [earned 5 cycles]
View Answer
SixBeeps (5223)

You have two options:
1.) Move dont_work work = new dont_work(); into the main function
2.) Mark work as a static variable

Right now, work is an instance variable of the Main class, but because main is a static function, you're not allowed to use it.