You cannot overload variables. At your approach, you must give them a different name, and then overload the method getMatrixfor different types.
Better use Java Generics:
public class Matrix<T> {
private T[][] matrix;
public T getMatrix() {return matrix;}
...
}
and then create objects of all types Matrix<Integer>, Matrix<Double>etc.
source
share