What happens when you try to compile and run this code:

public class Main {
    public static void main( String[] args ) {
        byte i = 2;
        byte j = 2;
        byte k = i * j;
        System.out.println(k);
    } 
}
Explanation
Before performing any arithmetic operations of the value of typebyte, short, char are automatically converted to the type int. Therefore, the result of the multiplication will also be of type int and then at compilation time the error of type mismatch will be found of variable byte k it's impossible to assign a value of type int.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback