java - When we use Referrence type and Object Type -


this question has answer here:

i having doubt regarding arraylist , list. in case should use arrarylist like:

arraylist obj = new arraylist(); 

and in case should use list interface.

list obj =  new arraylist(); 

after googling , study found nothing... please let me know difference between them.

thanks in advance :-)

if need call method specific implementation, use implementation.

when write :

list obj =  new ... //arraylist() or linkedlist() 

the compiler knows obj list. hence, cannot use methods specific 1 implementation.

for example, if need access last element of linkedlist, need declare :

linkedlist = obj = new linkedlist(); 

now, obj linkedlist. hence, can use obj.last().


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -