Why Java object class remains same after casting?
问题 I tried to upcast an objet. But at runtime object class is remained as a derived class. Derived drv = new Derived(); Base base = (Base) drv; System.out.println("Class : " + base.getClass()); //prints -> Class : class packagename.Derived So Why class property didn't change? 回答1: So Why class property didn't change? Because the object hasn't changed, just the type of the reference you have to it. Casting has no effect at all on the object itself. In Java, unlike some other languages (thankfully