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

two trains are 2 kms apart. Speed of one train is 20m/s and the other train is running at 30 m/s. Lengths of the trains are 200 and 300m. In how much time do the trains cross each other?

0 Answers   Infosys,


There are 8 balls that look identical. One of them weighs less than the others. Given a weighing scale, how will you find this ball.

21 Answers   Google, Infosys, Mind Tree, Sapient, Vatika, Wipro,


there is a safe with a 5 digit No. The 4th digit is 4 greater than second digit, while 3rd digit is 3 less than 2nd digit. The 1st digit is thrice the last digit. There are 3 pairs whose sum is 11. Find the number. Ans) 65292.

0 Answers   Infosys,


If the total distance of a journey is 120 km .If one goes by 60 kmph and comes back at 40kmph what is the average speed during the journey?

0 Answers   3i Infotech, Canara Bank, Geodesic,


find 70.56/ 11.2 =?

0 Answers   Canara Bank,






sir, i need help in preparing the exam .so, please help me by sending some question papers to my mail address neela_david@rediffmail.com

1 Answers   Banking, Central Bank of India,


mukesh and anil ambani invested amount in business and made in the ration 17:13 and made some profits. if mukesh earned 800 rs more than anil. then what is the profit they have earned....?

2 Answers  


(3x/(x+6))-(x/(x+5))=2 then find the value of x?

2 Answers  


if START = WALKA and BUDPI = XZFMR Then STUPID = ?

0 Answers   Baan Infotech,


There are 100 doors all are closed. The below action is taken 1) all are opened 2)all multiple of 2's are togelled ie if open close or viceversa .....100 times. What is the status of the door after 100th.

7 Answers   Vizag Steel,


If 13 = 13w/(1-w) ,then (2w)2 = ?

0 Answers   Cisco,


The ratio between two numbers is 5:7 and their product is 560. What is the difference between these two numbers?

0 Answers   Wipro,


Categories