I’m making a basic program that requires the use of all the letters’ indices in the alphabet. I made an array and tried to add something to it, but NetBeans keeps saying that it “cannot find symbol: class “alphabet””. My code is similar to the following:
public class MyClass {
char[] alphabet = new char[26];
alphabet[0] = 'a';
// et cetera
public static void main(String[] args) {
// Stuff
}
}
Any ideas as to why NetBeans says no to the above? My bet is that I’ve gotten something very basic wrong, but I just can’t figure out what…
Edit: as requested, a more comprehensive code is posted. Sorry for the inconvenience.
You need to place
alphabet[0] = ‘a’;
in a method or constructor not the class block.
Also it cannot be the main method as this is an instance variable. E.g.: