extend a class and make members private
in
Programming Questions
•
1 year ago
I basically need a PVector, however i don't want people to be able to set the x, y or z directly like p.x = 10;
Instead of that i want them to force to use p.setPosX(10);
But i still like that the other methods of PVector are still present.
Now i could copy all the code from PVector and make x, y, and z private instead of public, this might be the easiest way.
If i use this:
- class CVector extends PVector {
- private float x;
- private float y;
- private float z;
- CVector(float x, float y, float z) {
- super(x, y, z);
- }
- }
Then i still can use:
- CVector cv;
- void setup() {
- smooth();
- cv = new CVector(50, 50, 0);
- ellipse(cv.x, cv.y, 5, 5);
- }
Only the ellipse is drawn at 0, 0 instead of 50, 50.
Is it possible in a way to make x, y and z private?
And the reason it doesn't work now, is that cause everything is a inner class in processing?
If it is it is no problem since i have to use it in java anyway, i just like testing out in processing.
1