Java Reference
In-Depth Information
Self-Test Exercises (continued)
What output would be produced by the following code (which is just an
exercise and not likely to occur in a program)?
ExerciseException e =
new ExerciseException("Do Be Do");
System.out.println(e.getMessage());
The class ExerciseException is on the website that comes with this text.
15. Suppose the exception class TestException is defi ned as follows:
public class TestException extends Exception
{
extra code
on website
public TestException()
{
super ("Test Exception thrown!");
System.out.println(
"Test exception thrown!!");
}
public TestException(String message)
{
super (message);
System.out.println(
"Test exception thrown with an argument!");
}
public void testMethod()
{
System.out.println("Message is " + getMessage());
}
}
What output would be produced by the following code (which is just an
exercise and not likely to occur in a program)?
TestException exceptionObject = new TestException();
System.out.println(exceptionObject.getMessage());
exceptionObject.testMethod();
The class TestException is on the website that comes with this text.
extra code
on website
16. Suppose the exception class MyException is defi ned as follows:
public class MyException extends Exception
{
public MyException()
{
super ("My Exception thrown!");
}
(continued)
Search WWH ::




Custom Search