Check out this example from "sandeep mock exam"
class MyClass
{
public static void main(
String []args)
{
final int i = 100;
byte b = i;
System.out.println("i ="+b);
}
}
ans : o/p i =100
BUT
class MyClass
{
public static void main(String []args)
{
int i = 100;
byte b = i;......(1)
System.out.println(b);
}
}
I get a compiler error as Incompatible type declaration, so when I cast line (1) as byte b = (byte)i; it works fine with o/p 100
why is this strange behaviour with " final keyword"?, I am confused.
can somebody clear my doubt?
Thanks in advance
satheesh