In the following code, implicit typecasting for integer 9 takes place and is assigned to a byte data type variable of size 8 bits.
class Demo1
{
public static void main(String args[])
{
byte b=9;
System.out.println(b);
}
}
The code is happily compiled and executed.
but when I wrote the following code, it gave me a compilation error
class Demo2
{
void func1(byte b)
{
System.out.println(b);
}
public static void main(String[] args)
{
Demo2 d1=new Demo2();
d1.func1(9);
}
}
please explain to me why implicit (auto typecasting) does not occur in the last code?
Thanks to everyone pending.
source
share