+ 1
Explain this upcasting!!!
why Animal a = new Cat(); instead of Cat a = new Cat(); What is the difference? Why do we do the former?
1 Odpowiedź
+ 5
It depends on what you plan on doing. Making a Cat it's parent type allows for code that doesn't need to know whether it is processing a Cat or Dog to process either. If you declared it as Cat, the code would have to be written twice (both versions for Cat and Dog.)