They are both the same. This is a case of automatic type conversion down.
A a1 = (A) b; // Explicit type conversion A a2 = b;
In both cases, the types a1 and a2 are A. Therefore, the additional characteristics of B are lost anyway.
You will recognize the difference if you do an upcast cast that is not automatic. consider the following example.
Car v1 = new car (); // Correct. boost or implicit casting
Car v2 = new car ();
Car c0 = v1; // Invalid compile-time error "Mismatch Type" // Explicit or decreasing Car c1 = (Car) v1 // Right. understatement or explicit casting. v1 has car knowledge on line 1
Car c2 = (Car) v2; // Invalid Runtime ClassCastException exception because v2 does not know Car.
Bus b1 = new BMW (); // Invalid compile-time type mismatch
Car c3 = new BMW (); // Correct. Acceleration or implicit casting
Car c4 = (BMW) v1; // Invalid runtime exception ClassCastexception
Object o = v1; // v1 can only go up to the parent Car c5 = (car) v1; // v1 can be disabled for the car on line 1
source share