Why we declare in the way List ab = new ArrayList(); what is the use of it?



Why we declare in the way List ab = new ArrayList(); what is the use of it?..

Answer / sravani gupta

When you declare List l = new ArrayList() l is limited to the methods provided by the interface List, while when you declare it ArrayList al = new ArrayList() it can use all methods and fields in an arraylist.

When you declare it List l then you afford yourself more flexibility as you can change out the ArrayList for something more appropriate at a later date if you want to without breaking any code

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More General Aptitude Interview Questions

Refer to the figure below. A ship started from P and moves at a speed of I miles per hour and another ship starts from L and moving with H miles per hour simultaneously .Where do the two ships meet? ||—g—||—h—||—i—||—j—||—k—||—l—|| PG H I J K L are the various stops in between denoted by || . The values g, h, i, j, k, l denote the distance between the ports. explain how this question can b solved....

3 Answers   TCS,


if any one got the syllabus of deputymanager IT in punjab national bank please mail me,if u have any learning material of IT Officer (bank) please mail to me i will be very thankful(agarwal.nimish@yahoo.co.in)_

0 Answers  


How many different 9 digit numbers can be formed from the number 223355888 by re-arranging its digits so that the odd digits occupy even position?

0 Answers   TCS,


a sum 's' is devided into 4 parts.second person gets Rs 10 more than first.3rd person is Rs 10 more than second, 4th is 10 more than 3rd. how much amount do 1st person get?

22 Answers   Elin, Infosys, Wipro,


The ratio of cost price to the market price of an article is 4: 5. What is the profit percentage if the ratio of the profit percentage on selling the article to the discount allowed on it is 5: 4?

0 Answers   Cap Gemini,






Find the next number in the series 0,3,8,15,,24,48,63--

0 Answers   DSQ Software,


Wall of 88 m. Man climb 12 and falls by 8, when he will reach at top?

13 Answers   3D PLM, TCS, Zoho,


Jack & Jill went to the hill....In going to hill (upword Direction)...Jack went to the hill first nd waited for Jill for "x" hours.. Jack's speed was then twice of Jill.. In the down word direction Jill can go 3km in a hour, while Jack can go 1km in 1 hour.. Jill reach the ground 1st nd waited for Jack for "x" hours.. Total journey they traveled is 6 km.. Find the speed of Jack...

3 Answers   CTS,


A, B and C contract a work for Rs. 550. Together A and B are supposed to do 7/11th of the work. How much does C get? (a) Rs. 270 (b) Rs. 200 (c) Rs. 310 (d) Rs. 175 (e) None of these

5 Answers  


CALIBRATION PROCEDURE FOR HPLC

0 Answers   Sail,


A man said to woman " your only brother's son is my wife'sbrother". How is the woman related to the man's wife..

0 Answers   Ramco,


Number of digits with a 2 in them between 100 and 400?

0 Answers   Accenture,


Categories