1
Exam 1 Exam 1
- Average: 27.5 / 40
- Grade Range: 14 - 39
Question 1
- All true
– A class with an abstract method must be declared as abstract – An abstract class cannot be instantiated. – A subclass of an abstract class may be instantiated if it overrides all abstract methods and provides a body for each
Question 2
- FileReader input = new FileReader(args[0])
– Reader reads characters – FileReader reads characters from a File – The argument to FileReader is a filename
- In this case the filename is the first argument found on the
command line java className foo bar moo 7
args
args[0] args[1] args[2] args[3]
foo bar moo 7
Question 3
- Both false
– A finally block will always execute regardless
- f whether the exception is caught or not
– A try block can have an unlimited number of catch clauses, not a maximum of 2.
Question 4
- Answer is (b)
– The catch blocks are tested in turn, the first one that matches the subclass of Exception caught will be executed
- In the example, ArithmeticException is caught
- The first catch block is executed, the others are ignored
- “5” is printed
– The finally block is always executed
- “2” is printed
– After the try/catch/finally is done, execution continues with next statement.
- “1” is printed