How to initialize array in java when the class constructor has parameters?

后端 未结 4 953
耶瑟儿~
耶瑟儿~ 2021-02-04 09:28

I have this class constructor:

public Category(int max){
...
}

The thing is, I want to make an array of this class, how do I initialize it?

4条回答
  •  故里飘歌
    2021-02-04 10:23

    Initialize it as an array first

    Category[] categories = new Categories[4];
    categories[0] = new Category(max);
    

    Then initialize each individual element.

提交回复
热议问题