Hey! So I'm really new to Java, and I'm learning using Headstart Java. I'm working on a side project, which will eventually hopefully be a Pokedex, and I've just been going to it at the end of every chapter and using the stuff I've learned to work on it.
So I just read chapter 3, which is all about variables and teaches how to use arrays.
my question is, does an array have to be declared inside a method? Because I'm trying to create an array inside a class without any methods and without the main, and I continuously get errors. Here's a quick working of my code that won't compile.
The error message focuses on
Telling me the 0 should be a ], the = is an illegal start of type, so on and so forth.
The program compiles completely fine if it's within a method, like this:
Or if I have
But I'm trying to practice working outside of main.
So does an array have to be within a method, or am I just daft, and missing something obvious?
Thanks in advance.