I need a clarification on thhe following two questions from the mock exam - JExam:
Q1)
Suppose a MyException should be thrown if Condition() is true, which statements do you have to insert ?
1: public aMethod {
2:
3: if (Condition) {
4:
5: }
6:
7: }
a)throw new Exception() at line 4 - myans
b)throws new MyException() at line 4 *
c)throw new MyException() at line 6
d)throws new Exception() at line 2
e)throws MyException at line 1 *
My answers are a & e. But as per the exam its b & e. please clarify
Q2)
Consider the following piece of code and select the correct statements.
1. Object o = new
String("abcd");
2. String s = o;
3. System.out.println(s);
4. System.out.println(o);
a)The following is displayed:
abcd
abcd
b)The code fails to compile at line 1.
c)The code fails to compile at line 2
d)The code fails to compile at line 4.
e)The code can be made to compile by changing line 1 to the following:
String o = new String("abcd");
My answers are c & e. But the JExam says only c is correct. Please clarify.
Regards,
JAI