Electrical FireQuality AssuranceSample Test 3 |
|
class IndexOutOfBounds
{
static final int len=10;
int method()
{
Object arrayref[] = new Object[len];
Oject obj;
try {
obj = arrayref[-1];
return 2;
} catch (ArrayIndexOutOfBoundsException e){
}
try {
obj = arrayref[len];
return 2;
} catch (ArrayIndexOutOfBoundsException e) {
}
return 0;
}
public static void main(String[] args)
{
if ( method() == 0 ) System.out.println("passed");
else System.out.println("failed");
}
}