Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create multidimensional array of inner class objects in java

Tags:

java

arrays

everything is the title
java tutorial says:

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

this doesn't 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];
    }
}
like image 263
ryskajakub Avatar asked Dec 29 '25 11:12

ryskajakub


2 Answers

Just

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

It is when you need to create instance of pixel object, you'll have to write:

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

Also, it is a good idea to follow common Java naming conventions, e.g. use upper case for class/type names.

like image 196
Eugene Kuleshov Avatar answered Jan 01 '26 03:01

Eugene Kuleshov


Should be something like this:

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

}

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

like image 23
Mike Avatar answered Jan 01 '26 05:01

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!