Sunday, March 23, 2014

OCJP practice question #4

11:09 PM

What will be the output of following java program ?? 
                                   
                                     OCJP TRICKY QUESTIONS


This Program complies fine, but throws a run time exception saying ArrayStoreException

This particular exception comes when we try to store the wrong type of object into an array of objects

Here the asList() method do not convert Array into List , it just virtually shows a List represents of an Array. 

Arrays have a characteristics that they are
  • fixed in size
  • can store only homogeneous(similar type) values.  
That's why we get exception at line l.add("word");

Never get confused in exam, practice hard is the mantra to get success in OCJP.

0 comments :

Post a Comment

 

© 2014 DieHardTechy . All rights resevered. Designed by Diehardtechy