i am trying to create a class system like this:
public class Matrix {
private int[][] m;
public Matrix(int rows, int cols) {
//constructor
}
public int get(int row, int col) {
return m[row][col];
}
}
public class Vector extends Matrix {
public Vector() {
//constructor
}
public int get(int index) {
return super.get(0, index);
}
}
I want the Matrix.get(row, col) function to be public, but i don't want it to be public through the Vector class. I don't want this to be possible:
Vector v = new Vector();
int x = v.get(1, 1);
The private access modifiers doesn't help me, because it doesn't make the method available outside of the Matrix class (except for its inheritors)
Any ideas on how it could be done?
Vectorshouldn't extendMatrix. Why do you want to achieve something like this? Sounds like an XY problem.Vectorclass and deprecate it.@Override @Deprecated /** * do not use method */ public int get(int row, int col) { return -1; }Vector's object not to see the parent'sgetmethod? I mean what is the specific problem you are trying to solve?