开发者

How to create multidimensional array of inner class objects in java

开发者 https://www.devze.com 2023-01-22 02:42 出处:网络
everything is the t开发者_StackOverflow中文版itle java tutorial says: OuterClass.InnerClass innerObject = outerObject.new InnerClass();

everything is the t开发者_StackOverflow中文版itle

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];
    }
}


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消