Sail E0 Webinar

MCQs

Total Questions : 24 | Page 2 of 3 pages
Question 11. Decrement operator, “, decreases value of variable by what number?
  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option A. -> 1


1


Question 12.

With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?

 1. x++;

 2. x = x + 1;

 3. x += 1;

 4. x =+ 1;

  1.    1, 2 & 3
  2.    1 & 4
  3.    1, 2, 3 & 4
  4.    3 & 2
 Discuss Question
Answer: Option D. -> 3 & 2


Operator ++ increases value of variable by 1. x = x + 1 can also be written in shorthand form as x += 1. Also x =+ 1 will set the value of x to 1.


Question 13. Modulus operator, %, can be applied to which of these?
  1.    Integers
  2.    Floating "“ point numbers
  3.    Both Integers and floating "“ point numbers.
  4.    None of the mentioned
 Discuss Question
Answer: Option D. -> None of the mentioned


Modulus operator can be applied to both integers and floating point numbers.


Question 14. Which of these statements are incorrect?
  1.    Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms.
  2.    Assignment operators run faster than their equivalent long forms.
  3.    Assignment operators can be used only with numeric and character data type.
  4.    None
 Discuss Question
Answer: Option D. -> None


None


Question 15. What is the output of this program?class increment {public static void main(String args[]){double var1 = 1 + 5; double var2 = var1 / 4;int var3 = 1 + 5;int var4 = var3 / 4;System.out.print(var2 + " " + var4); } }
  1.    1 1
  2.    0 1
  3.    1.5 1
  4.    1.5 1.0
 Discuss Question
Answer: Option C. -> 1.5 1


1.5 1


Question 16. What is the output of this program?class Modulus {public static void main(String args[]) {    double a = 25.64;int  b = 25;a = a % 10;b = b % 10;System.out.println(a + " "  + b);} }
  1.    5.640000000000001 5
  2.    5.640000000000001 5.0
  3.    5 5
  4.    5 5.640000000000001
 Discuss Question
Answer: Option A. -> 5.640000000000001 5


Modulus operator returns the remainder of a division operation on the operand. a = a % 10 returns 25.64 % 10 i:e 5.640000000000001. Similarly b = b % 10 returns 5.


Question 17. What is the output of this program?class increment {public static void main(String args[]) {        int g = 3;System.out.print(++g * 8);} }
  1.    25
  2.    24
  3.    32
  4.    33
 Discuss Question
Answer: Option C. -> 32


Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32.


Question 18. Which of these is not a bitwise operator?
  1.    &
  2.    &=
  3.    !=
 Discuss Question
Answer: Option C. -> !=


x is initialized to 10 then increased by 1 by ++ operator making it 11. x is again decreased by ” operator making it 10, next x is incremented by post increment and intialized to y, here the value of x obtained before increment operator is executed, so value of y is 10 and value of x is 11.


Question 19. What is the output of this program?class Output {public static void main(String args[]) {    int x , y;x = 10;x++;--x;y = x++;System.out.println(x + " " + y);} }
  1.    11 11
  2.    10 10
  3.    11 10
  4.    10 11
 Discuss Question
Answer: Option C. -> 11 10


x is initialized to 10 then increased by 1 by ++ operator making it 11. x is again decreased by ” operator making it 10, next x is incremented by post increment and intialized to y, here the value of x obtained before increment operator is executed, so value of y is 10 and value of x is 11.


Question 20. Which of these is returned by greater than,
  1.    Integers
  2.    Floating - point numbers
  3.    Boolean
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Boolean


All relational operators return a boolean value i:e true and false.


Latest Videos

Latest Test Papers