Java Reference
In-Depth Information
Self-Test Exercises
21. What output will be produced by the following code? (The defi nition of the
class NegativeNumberException is given in Display 9.9 .)
int n;
try
{
n = 42;
if (n > 0)
throw new Exception();
else if (n < 0)
throw new NegativeNumberException();
else
System.out.println("Bingo!");
}
catch (NegativeNumberException e)
{
System.out.println("First catch.");
}
catch (Exception e)
{
System.out.println("Second catch.");
}
System.out.println("End of exercise.");
22. Suppose that in Self-Test Exercise 21 , the line
n = 42;
is changed to
n = -42;
How would this affect the output?
23. Suppose that in Self-Test Exercise 21 , the line
n = 42;
is changed to
n = 0;
How would this affect the output?
 
Search WWH ::




Custom Search