Look at the following two cases...
Case: 1
In the above code, the instance of ArrayList is referred by ArrayLiist reference variable. Now suppose there is a slight change in ur requirement. Instead of ArrayList u want to use LinkedList, then u have to make changes at two different places in ur code. An ArrayList reference variable can't refer ny LinkedList instances.
U code will become..
Case 2:
change at one place only. Only change ArrayList constructor to LinkedList constructor like this.
This is the obvious advantage with second code.
One more thing in case 2, polymorphic feature of
java is used which is not in case 1.
regards
Naseem Khan
[ May 20, 2006: Message edited by: Naseem Khan ]