Explicit Type Conversion of sub class object to super class in java
问题 Consider below code: public class Test{ public static void main(String str[]){ B b = new B(); A a1 = (A)b;//Explicit type conversion A a2 = b; } } class A{} class B extends A{} In the above code are the two line: A a1 = (A)b;//Explicit type conversion A a2 = b; Equivalent? If not then what is the difference between the two and if yes then is there any scenario in java where we need to explicitly convert a sub class object into a super class object ? 回答1: The explicit type casting of the