Why up casting cause error here??
the best example https://code.sololearn.com/cge5K9ARPXlp/?ref=app
1) This is not casting, this is inheritance/polymorphism. Anywho, the actual error is because you have 2 objects named "obj2". change: a obj2 = new b(); to: a obj3 = new b(); There was also no reason to create the first 2 objects, they don't do anything.
This is nt up casting