| |
GeekInterview.com > Interview Questions > J2EE > Core Java
| Print | |
Question: Array List Collections
Answer: What is Use of declaring an array list object like List list = new ArrayList() rather than creating object like ArrayList arr = new ArrayList(); |
| May 05, 2008 15:18:54 |
#1 |
| rariedel |
Microsoft Expert Member Since: May 2008 Total Comments: 8 |
RE: Array List Collections |
In the simple example given, there is no particular advantage; however, in many situations it is often useful to interact with the derived class using only the interface contract from which is was derived.
Using constructs of this type are useful when it is not known in advance which of its many potential derived class implementations will be actually be instantiated. This allows generic programming constructs to be applied to a plethora of potential run-time variations. |
| |
Back To Question | |