1
visibility

What will be the output of the following program?

class MyClass{
public static void main(String []args){
int i = 34.0,j = 7,k;
k = i % j;
System.out.println(“k = ” + k );
}
}

  • k = 4

  • k = 0

  • k = 6

  • The program will not compile.

Inside main a variable i is declared which is of type int. So the value that i can hold is any integer value. But i is assigned to 34.0 which is of type floating point. This leads to mismatch of type. So compilation error occurs.