For example
public class parentClass{
//stuff done
}
public class derivedClass extends parentClass{
// has data that parentClass does not
}
// some function
public parentClass foo(parentClass myVar){
return myVar
}
// ... later ...
{
...
derivedClass dClass1 = new derivedClass();
parentClass pClass = foo(dClass1);
derivedClass dClass2 = (derivedClass)pClass;
...
}
Was data lost between dClass1 and dClass2? I am not sure, I think the answer is no. I know that if I was using doubles and ints then data IS lost, but that isn't using pointers and objects, so I wasn't sure.
You cant cast objects so you can't lose data. All you can do is cast the reference to an object and this doesn't alter it in any way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With