Consider the following piece of code Consider the following
Consider the following piece of code:
Consider the following piece of code: String [] data ={\"100\", \"200\", \"222\", \"232\", null, \"250\"}; try {try{for (int i=0;iSolution
Answer:
100
200
222
232
Unknown exception was encounterd.
Explanation:
data string array length is 6.
in for loop, we are iterating each string and displaying.
at i=0, String 100 will print
at i=1, String 200 will print
at i=2, String 222 will print
at i=3, String 232 will print
at i=4, Strign value is null. we aplied toString method on null object hence it will throw NullPointerException. Since we did not handle NullPointerException. The parent class Exception will catch it and handle it and print th emessage \"Unknown exception was encounterd.\".
If we have any value at i =4 then we would have got the exception ArrayIndexOutOfBoundsException.
Becuase or array size is 6 and index will startt from 0 to 5.
But in our case, we are running loop from 0 to 6. At i=6, we will get ArrayIndexOutOfBoundsException exception if we have value at i = 4.
![Consider the following piece of code: Consider the following piece of code: String [] data ={\ Consider the following piece of code: Consider the following piece of code: String [] data ={\](/WebImages/16/consider-the-following-piece-of-code-consider-the-following-1028570-1761532803-0.webp)