package net.dharmaraj;
public class MyTest {
public void myTest(int[] increment) {
increment[1]++;
}
public static void main(String args[]) {
int myArray[] = new int[1];
MyTest mt = new MyTest();
mt.myTest(myArray);
System.out.println(myArray[0]);
}
}
What is the result when you compile and run the following code?
A) Compile time error
B) Runtime error
C) ArrayOutOfBoundsException
D) Prints 1 on the screen
Ans:-C
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at net.dharmaraj.MyTest.myTest(MyTest.java:5)
at net.dharmaraj.MyTest.main(MyTest.java:12)
No comments:
Post a Comment