Sail E0 Webinar

MCQs

Total Questions : 65 | Page 5 of 7 pages
Question 41.


What is the output of this program?


class operators {
public static void main(String args[])
{
int x = 8;
System.out.println(++x * 3 + " " + x);
}
}
  1.    24 8
  2.    24 9
  3.    27 8
  4.    27 9
 Discuss Question
Answer: Option D. -> 27 9

Operator ++ has higher precedence than multiplication operator, *, x is incremented to 9 than

multiplied with 3 giving 27.
output:
$ javac operators.java
$ java operators
27 9


Question 42.


What is the output of this program?


class bitwise_operator {
public static void main(String args[])
{
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + " " + var2);
}
}
  1.    42 42
  2.    43 43
  3.    42 -43
  4.    42 43
 Discuss Question
Answer: Option C. -> 42 -43

Unary not operator, ~, inverts all of the bits of its operand. 42 in
binary is 00101010 in using ~

operator on var1 and assigning it to var2
we get inverted value of 42 i:e 11010101 which is -43

in decimal.
output:
$ javac bitwise_operator.java
$ java bitwise_operator
42 -43


Question 43.


What is the output of this program?


class operators {
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
int var3;
var3 = ++ var2 * var1 / var2 + var2;
System.out.print(var3);
}
}
  1.    10
  2.    11
  3.    12
  4.    56
 Discuss Question
Answer: Option C. -> 12

Operator ++ has the highest precedence than / , * and +. var2 is
incremented to 7 and then used

in expression, var3 = 7 * 5 / 7 + 7,
gives 12.
output:
$ javac operators.java
$ java operators
12


Question 44.


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

None
output:
$ javac increment.java
$ java increment
1.5 1


Question 45.

Which of these statements are incorrect?


  1.    Equal to operator has least precedence.
  2.    Brackets () have highest precedence.
  3.    Division operator, /, has higher precedence than multiplication operator.
  4.    Addition operator, +, and subtraction operator have equal precedence.
 Discuss Question
Answer: Option C. -> Division operator, /, has higher precedence than multiplication operator.

Division operator, /, has equal precedence as of multiplication
operator. In expression involving

multiplication and division evaluation
of expression will begin from right side when no brackets

are used.


Question 46.

Which of these statements are incorrect?


  1.    The left shift operator,
  2.    The right shift operator, >>, shifts all of the bite in a value to the right specified number of times.
  3.    The left shift operator can be used as an alternative to multiplying by 2.
  4.    The right shift operator automatically fills the higher order bits with 0.
 Discuss Question
Answer: Option D. -> The right shift operator automatically fills the higher order bits with 0.

The right shift operator automatically fills the higher order bit with
its previous contents each time

a shift occurs. This also preserves the
sign of the value.


Question 47.


What will be the output of the program?


class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
  1.    small
  2.    tiny
  3.    huge
  4.    Compilation fails
 Discuss Question
Answer: Option B. -> tiny

This is an example of a nested ternary operator. The second evaluation (x < 22) is true, 

so the "tiny" value is assigned to sup.

Question 48.

What is the order of precedence (highest to lowest) of following operators?
1. &
2. ^
3. ?:


  1.    1 -> 2 -> 3
  2.    2 -> 1 -> 3
  3.    3 -> 2 -> 1
  4.    2 -> 3 -> 1
 Discuss Question
Answer: Option A. -> 1 -> 2 -> 3

None.


Question 49.

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 50.

Decrement operator, -, decreases value of variable by what number?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option A. -> 1

None.




Latest Videos

Latest Test Papers