6. Flow control and Exceptions Flashcards

1
Q

Which exception is not defined in Java API:

IndexPositionException
NullPointerException
ArrayIndexOutOfBoundsException
ArrayOutOfBoundsException

A

IndexPositionException

ArrayOutOfBoundsException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What will be the output:

boolean x = false;
if (x = true) { System.out.println(“x = “ + x);}

A

x = true

Watch out for boolean assignments (=) that can be mistaken for boolean equality (==) tests. If the example was “if (x = false)..” then the if statement will be skipped.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What data types can evaluate switch statements ?

A

switch statements can evaluate only to enums or the byte, short, int,
char, and, as of Java 7, String data types. You can’t say this:

long s = 30;
switch(s) { }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which exceptions are unchecked and should we handle or declare rule.

A

Subtypes of Error or RuntimeException are unchecked, so the compiler doesn’t enforce the handle or declare rule. You’re free to handle them or to declare them, but the compiler doesn’t care one way or the other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly