Bitwise operators questions in java

Bit wise operators objective type questions and answers 

(1)

public class BitwiseOpe {
    public static void main(String[] args) {
         int a=010;
         Integer b=10;
         double d=~a|(b=a)<<2+b;
         System.out.print(d);
    }
}

What will output when you compile and run the above code?

(a)32768.0
(b)-9.0
(c)1.0
(d)Compiler error






Answer: (b)

(2)

public class BitwiseOpe {
    public static void main(String[] args) {
         int a=010;
         char c='a';
         double d=-c%-2.D+(a^=2)-2;
         System.out.print(d);
    }
}

What will output when you compile and run the above code?

(a)-7.0
(b)-8.0
(c)-9.0
(d)Compiler error






Answer: (a)

(3)

public class BitwiseOpe {
    public static void main(String[] args) {
         int a=010;
         char c='0';
         double d=++a + 2.0^c;
         System.out.print(d);
    }
}

What will output when you compile and run the above code?

(a)61.0
(b)59.0
(c)59.000000
(d)Compiler error






Answer: (d)

(4)

public class BitwiseOpe {
    public static void main(String[] args) {
         int j=10;
         j&=j|3;
         System.out.print(j);
    }
}

What will output when you compile and run the above code?

(a)11
(b)10
(c)true
(d)Compiler error





Answer: (b)

(5)

public class BitwiseOpe {
    public static void main(String[] args) {
         byte a=010,b=-12;
         int c=a|b;
         System.out.print(c);
    }
}

What will output when you compile and run the above code?

(a)12
(b)-4
(c)-12
Post a Comment