1
I know that Upcasting is to convert a subclass object to the superclass and Downcasting is to convert a superclass object to the subclass.
But in relation to the loss of values and the like, as it turns out?
Example: We have the superclass Carro
and the subclass CarroMelhorado
.
CarroMelhorado
is a Car, but with more things. But if I speak Carro c1 = new CarroMelhorado();
from now on that C1 gains new attributes and methods that can be used ?
And in another case: CarroMelhorado cm1 = new Carro()
here would be a Downcasting, only cm1 of the type CarroMelhorado
has more than Carro
doesn’t have, at all CarroMelhorado
being a Carro
, with that assignment cm1
would lose all their stuff "the most"?
The examples given are not about up or downcasting. I recommend reading the following link to better understand the concepts: What is upcasting and downcasting in the Java language?
– user28595
Only a constructive criticism: the word "lose" is not a noun. The correct one would be "loss".
– Sam
All right, and what would be a real application of this and for what purpose ? I am layman in the subject, I wanted to understand in practice and theory, in the course I am doing explains Upcasting and Downcasting superficially, I visualize better with real examples.
– Kevin Ricci