I have a question about cloning. If I have a super class called MotorVehicle who has :
private Engine engine= new Engine();
I also have a subClass called Car. I want to be able to clone the Car subclass and also the engine, is there a way to do this?
Ive tried the following but cant do it because Engine is declared private in the MotorVehicle.
public Object clone()
{
try{
Car cloned= (Car)super.clone();
cloned.engine=(Engine)engine.clone();
}
catch(CloneNotSupportedException e){
return null
}
}
Of course I also have a constructor which does super(engine). Is there a way I can clone the engine without being in MotorVehicle?
Thanks to anyone who responds.
private Engine engine= new Engine();
I also have a subClass called Car. I want to be able to clone the Car subclass and also the engine, is there a way to do this?
Ive tried the following but cant do it because Engine is declared private in the MotorVehicle.
public Object clone()
{
try{
Car cloned= (Car)super.clone();
cloned.engine=(Engine)engine.clone();
}
catch(CloneNotSupportedException e){
return null
}
}
Of course I also have a constructor which does super(engine). Is there a way I can clone the engine without being in MotorVehicle?
Thanks to anyone who responds.