I have a class Vector with a constructor
Vector(int dimension) // creates a vector of size dimension
I have a class Neuron that extends the Vector class
public class Neuron extends Vector {
public Neuron(int dimension, ... other parameters in here ...) {
super(dimension);
// other assignments below here ...
}
}
What I want to be able to do is assign the Vector in the Neuron class a reference to another Vector. Something along the lines of
public Neuron(Vector v, ... other parameters in here ...) {
super = v;
// other assignments below here ...
}
Of course, I can’t do this. Is there some work around? Even if I was not able to do this in the constructor of the Neuron class, that would probably be OK.
You need to create a copy constructor in the
Vectorclass:and then in
Neuronyou doYou may also consider using on composition instead of inheritance. In fact, that is one of the recommendations in Effective Java. In such case you would do
Related questions: