102). What is the output of relational operators?
[A]Integer
[B]Boolean
[C]Characters
[D]Double
Show Answer
Correct Answer: Boolean
Notes:
Answer: b
Explanation: None.
103). Which of these is returned by “greater than”, “less than” and “equal to” operators?
[A]Integers
[B]Floating – point numbers
[C]Boolean
[D]None of the mentioned
Show Answer
Correct Answer: Boolean
Notes:
Answer: c
Explanation: All relational operators return a boolean value ie. true and false.
104). Which of the following operators can operate on a boolean variable?
1. &&
2. ==
3. ?:
4. +=
[A]3 & 2
[B]1 & 4
[C]1, 2 & 4
[D]1, 2 & 3
Show Answer
Correct Answer: 1, 2 & 3
Notes:
Answer: d
Explanation: Operator Short circuit AND, &&, equal to, == , ternary if-then-else, ?:, are boolean logical operators. += is an arithmetic operator it can operate only on numeric values.
105). Which of these operators can skip evaluating right hand operand?
1. &&
2. ==
3. ?:
4. +=
Show Answer
Correct Answer: &&
Notes:
Answer: d
Explanation: Operator short circuit and, &&, and short circuit or, ||, skip evaluating right hand operand when output can be determined by left operand alone.
106). Which of these statements is correct?
1. &&
2. ==
3. ?:
4. +=
[A] true and false are numeric values 1 and 0
[B] true and false are numeric values 0 and 1
[C]true is any non zero value and false is 0
[D]true and false are non numeric values
Show Answer
Correct Answer: true and false are non numeric values
Notes:
Answer: d
Explanation: True and false are keywords, they are non numeric values which do not relate to zero or non zero numbers. true and false are boolean values.
107). What will be the output of the following Java code?
class Relational_operator
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
System.out.print(var1 > var2);
}
}
[A]1
[B]0
[C]true
[D]false
Show Answer
Correct Answer: false
Notes:
Answer: d
Explanation: Operator > returns a boolean value. 5 is not greater than 6 therefore false is returned.
output:$ javac Relational_operator.java
$ java Relational_operator
false
108). What will be the output of the following Java code?
class bool_operator
{
public static void main(String args[])
{
boolean a = true;
boolean b = !true;
boolean c = a | b;
boolean d = a & b;
boolean e = d ? b : c;
System.out.println(d + " " + e);
}
}
[A]false false
[B]true ture
[C]true false
[D]false true
Show Answer
Correct Answer: false true
Notes:
Answer: d
Explanation: Operator | returns true if any one operand is true, thus ‘c = true | false’ is true. Operator & returns a true if both of the operand is true thus d is false. Ternary operator ?: assigns left of ‘:’ if condition is true and right hand of ‘:’ if condition is false. d is false thus e = d ? b : c , assigns c to e , e contains true.
output:
$ javac bool_operator.java
$ java bool_operator
false true
109). What will be the output of the following Java code?
class ternary_operator
{
public static void main(String args[])
{
int x = 3;
int y = ~ x;
int z;
z = x > y ? x : y;
System.out.print(z);
}
}
Show Answer
Correct Answer: 3
Notes:
Answer: c
Explanation: None.
output:
$ javac ternary_operator.java
$ java ternary_operator
3
110). What will be the output of the following Java code?
class Output
{
public static void main(String args[])
{
int x , y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
[A]1
[B]2
[C]Runtime error owing to division by zero in if condition
[D]Unpredictable behavior of program
Show Answer
Correct Answer: 2
Notes:
Answer: b
Explanation: Operator short circuit and, &&, skips evaluating right hand operand if left hand operand is false thus division by zero in if condition does not give an error.
output:
$ javac Output.java
$ java Output
2
111). What will be the output of the following Java code?
class Output
{
public static void main(String args[])
{
boolean a = true;
boolean b = false;
boolean c = a ^ b;
System.out.println(!c);
}
}
[A]0
[B]1
[C]false
[D]True
Show Answer
Correct Answer: false
Notes:
Answer: c
Explanation: None.
output:
$ javac Output.java
$ java Output
false