Java认证模考试题(八)
文章作者 100test 发表时间 2007:03:14 17:02:44
来源 100Test.Com百考试题网
Question: 41
Given the following code:
public void fun ()
{
int i.
try
{
i=System.in.read ().
System.out.println(Location 1).
} catch (IOException e) {
System.out.println(Location 2).
} finally {
System.out.println(Location 3).
}
System.out.println(Location 4).
}
If an IOException occurs, what will be printed?
A. Location 1
B. Location 2
C. Location 3
D. Location 4
Explanation:
When an IOException occurs the Location 1 is skipped. Fist the exception is caught and the Location 2 is printed. Then the Location 3 in the block of finally is printed. Finally, the Location 4 is printed.
Correct Answer: B,C,D 41 of 60
Question: 42
If the method func() is allowed to throw out the IOException, which declaration of this method can used?
A. public int func(int i)
B. public int func(int i) throw IOException
C. public int func(int i) throw Exception
D. public int func(int i) throws IOException
E. public int func(int i) throws Exception
Explanation:
The throws keyword should be used when declaration of a method. In the declaration IOException and its superclass Exception can be used.
Correct Answer: D,E 42 of 60