turtlered9
turtlered9

Reputation: 9

How would i instantiate and pass a 2d array to a method?

So in my code i have a constructor that is supposed to take two 2d arrays and a enum of a quadrant i already have set up. I have set up my constructor like this.

public ThreadOperation(int[][] a, int[][] b, Quadrants x){
    
    }

I have instantiated a new object that looks like this

ThreadOperation T1 = new ThreadOperation(int[][],int[][],Quadrants.TopLeft);

i keep getting the error error: '.class' expected. Im new to programming so i guess im just having trouble trying to figure out how to pass the two 2d arrays over to the constructor without giving me an error. These are just placeholders so i can compile.

Upvotes: 0

Views: 58

Answers (1)

Ankur Saxena
Ankur Saxena

Reputation: 197

check this out , you would need to initialise :-

public class Operation {

    public static void main(String[] args) {

        int [][]a = new int[2][2];
        int [][]b = new int[3][3];
        TestMe testMe = new TestMe(a,b,Month.January);
    }
}
class TestMe {
    int [][] a;
    int [][] b;
    Month month;

    public TestMe(int[][] a, int[][] b, Month month) {
        this.a = a;
        this.b = b;
        this.month = month;
    }
}

enum Month {
    January
}

Upvotes: 1

Related Questions