Question: 1.. Which exception occurs when an attempt is made to access an array position that is NOT found? A)ArithmeticException B)ArrayIndexOutOfBoundsException C)ClassCastException D)IndexOutOfBoundsException E)NullPointerException 2. What
1.. Which exception occurs when an attempt is made to access an array position that is NOT found?
A)ArithmeticException
B)ArrayIndexOutOfBoundsException
C)ClassCastException
D)IndexOutOfBoundsException
E)NullPointerException
2. What are the values of x and y after the following code is executed? int x = 0; int y = 6; while( (y != 0) && (x / y >= 0) ) { x += 1; y = 2; }
A)x = 4 and y = 2
B)x = 3 and y = 0
C)x = 2 and y = 2
D)x = 0 and y = 6
E)An ArithmeticException will be thrown before execution is complete.
3. Which statements are true about a method's postcondition?
- It can only be met if a value is returned.
- It can only be achieved if the preconditions are met.
- It should be true after the method code is executed.
A)I only
B)III only
C)I and II only
D)II and III only
E) I, II, and III
4. Which exception is thrown when a method receives an invalid value?
A) ClassCastException
B) IllegalArgumentException
C)IllegalStateException
D) NoSuchElementException
E)NullPointerException
5. The following code segment will generate which runtime error? int [] numGames = new int[10]; int [] totalPoints = new int[10]; System.out.println( totalPoints[2] / numGames[2] );
A)ArithmeticException
B)ArrayIndexOutOfBoundsException
C)ClassCastException
D)IllegalArgumentException
E)NullPointerException
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
