A a = new B();// ^------ Here reference "a" holds instance of type BB b = (B)a; // so now casting is safe, now JVM is sure that `b` reference can// safely access all members of B class
Object[] arr = new String[] { "ab", "cd" }; //OK - because// ^^^^^^^^ `arr` holds array of subtype of Object (String)String[] arr2 = (String[]) arr; //OK - `arr2` reference will hold same array of same type as// reference