This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
i understand why i'm getting the error on line no 2 cause the found return value is character and the return type is byte
but shouldn't i get the complile time error at line 1 also cause it is also returning the character value even though the return type is byte.... [ September 05, 2007: Message edited by: deeksha mehra ]
No, line 1 compiles fine. The variable is char but it is a final that is assigned a literal, so it is resolved at compile time. Java knows that the return value cannot be any other than \u0001, or 1. And so it knows that it fits a byte. Change that value to \u0101 and you will see it won't compile, because it knows the return value doesn't fit a byte.