Tech Me More

To quench our thirst of sharing knowledge about our day to day experience & solution to techincal problems we face in our projects.

Advertise with us !
Send us an email at diehardtechy@gmail.com

Sunday, March 23, 2014

OCJP practice question #4

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.

No comments: