Peter Voorwinden

Greenhorn
+ Follow
since Aug 02, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Peter Voorwinden

Greame,
I think you're wrong in your explanation of | |. In case of operator | |, if the left operand evaluates to true, the complete expression will be true, no matter what the right operand will be. So there's no need to check the right operand (and it won't be evaluated!). In case of operator && both operands need to be true for the complete expression to be true. So if the left operand is true, it still needs to evaluate the right operand to be able to determine the value of the complete expression.
So in case of answer 3: if s == null, then the left operand evaluates to false, so the right operand will be evaluated and will result in a NullPointerException.
In case of answer 4: if s == null, the left operand evaluates to true and the right operand will not be evaluated.
So I think the answer should be 1, 2 and 3
Be careful: suppose the exception was not caught by one of the catch blocks, the finally block would get executed, but the line(s) after the try/catch/finally would not get executed, but control flow would jump to the end of the method.
Just FYI.
Peter
Hi Sherin,
Ans 3 is incorrect, because you're trying to add a method with the same signature to the same class, although the name of the second parameter is different, but that doesn't count in overloading.
Ans 4 is correct, but is not a case of overloading, because the name of the method is different.
Hope this helps,
Peter
[This message has been edited by Peter Voorwinden (edited September 15, 2000).]
Hi Bala,
Answer to q1: No you cannot instantiate an interface, although you can have a reference variable of type interface X, that can be assigned an object of a class that implements this interface.
Answer to q2: This works. The compiler is able to convert the character '/' to a string object and it will concatenate these strings to one string. and assign its reference to variable s.
Hope this helps,
Peter
I agree with Ramani. Answer B is incorrect because you're trying to initialize a reference to the wrapper class of type Boolean with a boolean value. If you want to make this work you should do something like:

Peter
Hi Anil,
Look at the JLS section 15.23:
The <code>&&</code> operator is like <code>&</code> (�15.22.2), but evaluates its right-hand operand only if the value of its left-hand operand is <code>true</code>. It is syntactically left-associative (it groups left-to-right). It is fully associative with respect to both side effects and result value; that is, for any expressions a, b, and c, evaluation of the expression <code>((</code>a<code>)&&(</code>b<code>))&&(</code>c<code>)</code> produces the same result, with the same side effects occurring in the same order, as evaluation of the expression <code>(</code>a<code>)&&((</code>b<code>)&&(</code>c<code>))</code>.

    <pre>
    <em>ConditionalAndExpression:
    InclusiveOrExpression
    ConditionalAndExpression && InclusiveOrExpression
    </em></pre>
    Each operand of <code>&&</code> must be of type <code>boolean</code>, or a compile-time error occurs. The type of a conditional-and expression is always <code>boolean</code>.
    At run time, the left-hand operand expression is evaluated first; if its value is <code>false</code>, the value of the conditional-and expression is <code>false</code> and the right-hand operand expression is not evaluated. If the value of the left-hand operand is <code>true</code>, then the right-hand expression is evaluated and its value becomes the value of the conditional-and expression. Thus, <code>&&</code> computes the same result as <code>&</code> on <code>boolean</code> operands. It differs only in that the right-hand operand expression is evaluated conditionally rather than always.
    So the lines both evaluate to false, but for line 1 all operands are evaluated and for line 2 only b1, because since b1 is false, the complete expression will be false.
    Hope this helps!

    [This message has been edited by Peter Voorwinden (edited August 24, 2000).]
"str" + "ing" can be evaluated at compile time, so the compiler will make "string" of it. The same for "s" + "t" + "r" + "i" + "n" + "g".
Hello,
I was wondering if it is useful to use this cd-rom in preparation of the SJCP exam? Not in place of books, but in addition to them.