Please, explain the following problems from JQtest
Q1)
Imagine that there are two exception classes called Exception1 and Exception2 that descend from the Exception class. Given these two class definitions,
1. class First {
2. void
test() throws Exception1, Exception2 { . . . }
3. }
4. class Second extends First {
5. void test() { . . . }
Create a class called Third that extends Second and defines a test() method. What exceptions can Third's test method throw? Select one valid answer.
ans) no checked Exception, why?
Q2) "slight modified"
class test {
public static void main(
String arg[]) {
String args[]=
{"Mighty", "Mouse"};
Changer c = new Changer();
c.method(args);
System.out.println(args[0] + " " + args[1]);
}
static class Changer {
void method(String s[]) {
String temp = s[0];
s[0] = s[1];
s[1] = temp;
}
}
}
ans) prints Mouse Mighty , but why? I know this seems trival question but I'm thinking in terms of the copy of the reference of original array passed in as an argument. So my guess was that it wouldnt change the actual data values in the object array when using s[] in the local method.
thank you!