posted 21 years ago
Hi Again,
Answer is
22 d Compile-time error at 2. There is a compile-time error at 2. The short type variable, s, is not a compile-time constant, so it can not be assigned to type byte without an explicit cast. The statement, "return s;", is a return statement with an expression, s. A compile-time error occurs if the type of the expression is not assignable to the declared result type of the method. The declared result type of the method, m4, is byte. The return statement attempts to return the value of the short type variable, s. If a short value is a compile-time constant, and if the value falls within the range of type byte, then the short value is assignable to type byte. In method m4, variable s is not a compile-time constant, so the value of variable s is not assignable to type byte. While the declaration of method m4 produces a compile-time error, the declaration of method m2 does not; because the variable is a compile-time constant with a value, 2, that is assignable to type byte.
I can understand the explanation given above as "If a short value is a compile-time constant, and if the value falls within the range of type byte, then the short value is assignable to type byte."
But as explained " In method m4, variable s is not a compile-time constant", now is the variable s in m4 not compile time constant as it is passed as method argument (although it is a final variable ??)
Plz. clarify,I thought it to be constant
Thanks,
"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister