public class ByteTest
{
public static void main (
String rags[] )
{
byte b1 , b2 , b3 , b4 , b5 ;
b1 = 2 ;
b2 = 4 ;
b3 = ( byte ) ( b2 / b1 ) ; // ( 1 )
System.out.println ( " The value of b3 is " +b3 ) ;
b4 = ( byte ) ( b2 * b1 ) ; // ( 2 )
System.out.println ( " The value of b4 is " +b4 ) ;
b5 = ( byte ) ( b2 - b1 ) ; // ( 3 )
System.out.println ( " The value of b5 is " +b5 ) ;
}
}
if the l.h.s is byte , short or char datatype variable and the r.h.s is a int value , then implicit typecasting occurs and the int data is typecasted to appropriate data-type
the compiler when compiling the code doesn't evaluate the expressions at ( 1) , ( 2 ) , ( 3 ) , this evaluation is only done during run time , so during compilation it becomes necessary to make the compiler aware that the resultant data that is produced by the expression will go into a type-compatible variable