3 Mantras of Object typecasting

 A b = (c) d;

Mantra -1 (At Compile Time): the type of c and d must have some relationship (either parent to child or child to parent or same type), otherwise we will get a compile-time error. 

Mantra -2 (At Compile Time): the type of c must be the same or derived type of A, otherwise we will get a compile-time error. 

Mantra -3 (At RunTime): the underlying original object type of d must be either the same or derived type of c, otherwise we will runtime exception saying class cast exception.


Comments

Popular posts from this blog

public static void main(String [] args) - Full Explanation

Coding Problem 3 - Weather Observation Station 7 [HackerRank - SQL]

Date Range Picker In Angular 10