What is the result of the following code:

public class MainClass {
    public static void main(String args[]) {
        int k = 2;
        System.out.println( k << 3 >> k == k >> 1 << k);
    }
}
Explanation
The sequence of execution and results of operations are as follows:

1.    k << 3 = 16 (0000 0010b << 3 = 0001 0000b)
2.    16 >> 2 = 4 (0001 0000b >> 2 = 0000 0100b) 
3.    k >> 1  = 1 (0000 0010b >> 1 = 0000 0001b)
4.    1 << k = 4  (0000 0001b << 2 = 0000 0100b)
Because 4 = 4 the correct answer true.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes