How to create a multidimensional array of internal class objects in java

everything is a name
The java textbook says:

OuterClass.InnerClass innerObject = externalObject.new InnerClass ();

this does not work for me:

public class aching{
    class pixel{
        public char c;
        public int f;
    }
    public static void main(String[] args){
        aching a = new aching();
        aching.pixel[][] p = a.new pixel[1][1];
    }
}
+3
source share
2 answers

Simply

pixel[][] p = new pixel[1][1];

When you need to instantiate a pixel object, you will need to write:

p[0][0] = a.new pixel();

Also, it's nice to follow general Java naming conventions, for example. use uppercase for type / type names.

+5
source

There should be something like this:

public static void main(String[] args){
   pixel p[][] = new pixel[1][1];

}

Next, follow the convention, your class names should start with a capital letter.

+1
source

Source: https://habr.com/ru/post/1770960/


All Articles