0

I want to create a class that creates arrays and can implement functions on them. This class will support creating an array of another class.

What I have implemented to do this is several overloaded constructors:

  public BArray(String type, int rows, int columns)
  {
    String array[][] = new String[rows][columns];
  }
  public BArray(int type, int rows, int columns)
  {
    int array[][] = new int[rows][columns];
  }
  public BArray(double type, int rows, int columns)
  {
    double array[][] = new double[rows][columns];
  }
  public BArray (Class Student, int rows, int columns)
  {
    Class array[][] = new Class[rows][columns];
  }

How would I create an instance of this class with an array of classes (class Student)? I have tried

BArray students = new BArray(Student, 1, lines);

but that gives me an error, can not find symbol, on the word Student.

Ganlas
  • 51
  • 5
  • Didn't you just ask this question earlier? https://stackoverflow.com/questions/57261485/how-do-i-pass-in-a-class-to-make-an-array-of-classes – Mihir Kekkar Jul 30 '19 at 05:02
  • @MihirKekkar no, in my previous question I was asking would you set up the constructor within a class. Now I'm confused on how you would instantiate and use the class itself to create an array of classes. – Ganlas Jul 30 '19 at 05:04
  • 1
    The top answer on your previous question included a code snippet on creating an instance of your array class. `final Array strings = new Array<>(5, String.class);` was specifically for a String array, but you can change String.class to Student.class to instead create a Student array. – Mihir Kekkar Jul 30 '19 at 05:11

0 Answers0