Originally posted by Muralidhar Mandapati:
" A CAST ONLY CHANGES THE TYPE OF REFERENCE NOT THE CLASS OF THE OBJECT ".
This is the distinction between the type of a reference and the type of an object or instance. When you instantiate an object and assign a reference to it to a variable
the object (instance) that gets created has a permanent type: its class, ArrayList in the example. But since the object reference l is declared as List, you cannot use it to call methods declared only in ArrayList.
If you want to call those methods, you have to cast the reference. Casting tells the compiler that you expect the reference to point to an object with the given type or one of its subtypes, but it does not alter the object's type.