GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 478 of 484    Print  
Array List Collections
What is Use of declaring an array list object like
List list = new ArrayList() rather than creating object like ArrayList arr = new ArrayList();



  
Total Answers and Comments: 5 Last Update: July 05, 2008     Asked by: rgmanoj 
  
 Sponsored Links



 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
May 23, 2008 15:18:54   #1  
rariedel Member Since: May 2008   Contribution: 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.

 
Is this answer useful? Yes | No
May 26, 2008 06:14:34   #2  
zizou Member Since: May 2008   Contribution: 2    

RE: Array List Collections
Hi
this technique is much more advantageuous as it'easy to cast the created object in runtime easily to another subclass of the list super classs.

 
Is this answer useful? Yes | No
June 15, 2008 17:07:30   #3  
interviewprep9 Member Since: June 2008   Contribution: 4    

RE: Array List Collections
Can someone please explian more eloborately on this one? Using List list = new ArrayList(), will I be invoking list's methods or the ArrayList methods with the reference variable list
 
Is this answer useful? Yes | No
June 27, 2008 05:35:11   #4  
manjot.kr Member Since: June 2008   Contribution: 0    

RE: Array List Collections
List is an interface where as Arraylist is a class.
Arraylist implements all the methods in List...
So the arraylist's methods are invoked as the method body is present in Arralist

 
Is this answer useful? Yes | No
July 05, 2008 06:37:58   #5  
R.Raj Member Since: April 2008   Contribution: 1    

RE: Array List Collections
Yes,It is possible to invoke the methods of ArrayList using the reference variable list.
Infact it is used for that purpose only. 

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links



 
Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape