112). Which of these have highest precedence?
Show Answer
Correct Answer: ()
Notes:
Answer: a
Explanation: Order of precedence is (highest to lowest) a -> b -> c -> d.
113). What should be expression1 evaluate to in using ternary operator as in this line?
expression1 ? expression2 : expression3
[A]Integer
[B]Floating – point numbers
[C]Boolean
[D]None of the mentioned
Show Answer
Correct Answer: Boolean
Notes:
Answer: c
Explanation: The controlling condition of ternary operator must evaluate to boolean.
114). What is the value stored in x in the following lines of Java code?
int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
Show Answer
Correct Answer: 8
Notes:
Answer: d
Explanation: None.
115). What is the order of precedence (highest to lowest) of following operators?
1. &
2. ^
3. ?:
[A]1 -> 2 -> 3
[B]2 -> 1 -> 3
[C]3 -> 2 -> 1
[D]2 -> 3 -> 1
Show Answer
Correct Answer: 1 -> 2 -> 3
Notes:
Answer: a
Explanation: None.
116). Which of these statements are incorrect?
1. &
2. ^
3. ?:
[A]Equal to operator has least precedence
[B]Brackets () have highest precedence
[C] Division operator, /, has higher precedence than multiplication operator
[D]Addition operator, +, and subtraction operator have equal precedence
Show Answer
Correct Answer: Division operator, /, has higher precedence than multiplication operator
Notes:
Answer: c
Explanation: Division operator, /, has equal precedence as of multiplication operator. In expression involving multiplication and division evaluation of expression will begin from the right side when no brackets are used.
117). What will be the output of the following Java code?
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);
}
}
Show Answer
Correct Answer: 12
Notes:
Answer: c
Explanation: 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
118). What will be the output of the following Java code?
class operators
{
public static void main(String args[])
{
int x = 8;
System.out.println(++x * 3 + " " + x);
}
}
[A]24 8
[B]24 9
[C] 27 8
[D]27 9
Show Answer
Correct Answer: 27 9
Notes:
Answer: d
Explanation: 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
119). What will be the output of the following Java code?
class Output
{
public static void main(String args[])
{
int x=y=z=20;
}
}
[A]compile and runs fine
[B]20
[C]run time error
[D]compile time error
Show Answer
Correct Answer: compile time error
Notes:
Answer: d
Explanation: None.
120). Which of these lines of Java code will give better performance?
1. a | 4 + c >> b & 7;
2. (a | ((( 4 * c ) >> b ) & 7 ))
[A]1 will give better performance as it has no parentheses
[B]2 will give better performance as it has parentheses
[C]Both 1 & 2 will give equal performance
[D] Dependent on the computer system
Show Answer
Correct Answer: Both 1 & 2 will give equal performance
Notes:
Answer: c
Explanation: Parentheses do not degrade the performance of the program. Adding parentheses to reduce ambiguity does not negatively affect your system.
121). . What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
int a,b,c,d;
a=b=c=d=20;
a+=b-=c*=d/=20;
System.out.println(a+" "+b+" "+c+" "+d);
}
}
[A] compile time error
[B] runtime error
[C] a=20 b=0 c=20 d=1
[D]none of the mentioned
Show Answer
Correct Answer: a=20 b=0 c=20 d=1
Notes:
Answer: c
Explanation: Expression will evaluate from right to left.
output:
$ javac Output.java
$ java Output
20 0 20 1