How can I refer to the object on which I'm implementing the instance method. I wrote a class called MatrixMaker that looks like this:
package one;
public class MatrixMaker {
private int rows;
private int columns;
public MatrixMaker(int m, int n){
rows = m;
columns = n;
double[][] matrix = new double[rows][columns];
}
public void printer(){
for(int i = 0; i < rows; i++){
for(int j = 0; j < columns; j++){
System.out.print(matrix[i][j]);
}
System.out.println();
}
}
}
I initialized an object in this class using:
MatrixMaker matrix = new MatrixMaker(3,4);
My question is how do I use
matrix.printer();
to print the array. I can't seem to refer to the contents of the object inside the method printer(). Specifically the line:
System.out.print(matrix[i][j]);
double[][] matrixin your class scope. So place it whereprivate int columns;is.