Assignment-II Operators

Embed Size (px)

Citation preview

  • 8/7/2019 Assignment-II Operators

    1/3

    Questions On Operators

    Questions1. What is the value of 111 % 13?A. 3B. 5C. 7

    D. 92. What is the value of 9 + 8 % 7 + 6 ?A. 17B. 16C. 13D. 43. What is the value of y after execution of the following statements?

    4. int x = 5;5. int y = 4;6.y = x++;

    A. 4B. 5

    C. 6D. 74. What is the value returned by "abcd" instanceof Object ?A. "abcd"B. trueC. falseD. String5. What is the value of 8 | 9 & 10 ^ 11 ?A. 8B. 9C. 10D. 116. What is the output displayed by the following program?

    class Question {public static void main(String[] args) {int n = 7;n = 2;System.out.println(n);}}A. 0B. -1C. 14D. 64

    7. What is the value of -31 >>> 5 >> 5 >>> 5 >> 5 >>> 5 >> 5 ?A. NaNB. -1C. 3D. 10248. What is the value displayed by the following program?class Question {public static void main(String[] args) {int x = 0;boolean b1, b2, b3, b4;b1 = b2 = b3 = b4 = true;x = (b1 | b2 & b3 ^ b4) ? x++ : --x;System.out.println(x);}}A. -1

  • 8/7/2019 Assignment-II Operators

    2/3

    B. 0C. 1

    D. 29. What line of output is displayed by the following program?class Question {static boolean sideEffect(boolean b) {System.out.print(" side effect ");

    return b;}public static void main(String[] args) {boolean b1 = true;boolean b2 = false;if(b2 & sideEffect(b1)) System.out.println(1);else if(b1 | sideEffect(b2)) System.out.println(2);}}A. 1B. 2C. side effect 1D. side effect 2

    E. side effect side effect 1F. side effect side effect 2

    10. Which statement (exactly one) is true about the following program?class Question {public static void main(String[] args) {double d1 = 1.0;double d2 = 0.0;byte b = 1;d1 = d1 / d2;b = (byte) d1;System.out.print(b);}}A. It results in the throwing of an ArithmeticException .B. It results in the throwing of a DivideByZeroException .C. It displays the value 1.5 .

    D. It displays the value -1 .11.What is the result of the expression 5.4 + "3.2" ?A. The double value 8.6 .B. The String "8.6" .C. The long value 8 .

    D. The String "5.43.2" .12.What is the result of the following program?class Question {

    public static void main(String[] args) {int i = 7;int j = 8;int n = (i | j) % (i & j);System.out.print(n);}}A. 0B. 15C. An ArithmeticException is thrown.

    D. -1513.Suppose that classes X and Y are subclasses of Z and Z implements the W interface.Which of the following are true?A. A reference to an object of class X can be cast to a reference to an objectof class Y .B. A reference to an object of class Y can be cast to a reference to an object

  • 8/7/2019 Assignment-II Operators

    3/3

    of class X .C. A reference to an object of class X can be cast to a reference to an objectof class Z .D. A reference to an object of class Y can be cast to a reference to an objectof class Z .E. A reference to an object of class X can be cast to a reference to an objectof interface W .

    F. A reference to an object of class Y can be cast to a reference to an objectof interface W .G. A reference to an object of class Z can be cast to a reference to an objectof interface W .14. Which of the following are true?A. A reference to an array can be cast to a reference to an Object .B. A reference to an array can be cast to a reference to a Cloneable .C. A reference to an array can be cast to a reference to a String .

    D. None of the above.15. Which of the following are true?A. A reference to an array can be cast to a reference to an Object .B. A reference to an array can be cast to a reference to a Cloneable .C. A reference to an array can be cast to a reference to a String .

    D. None of the above.