Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Download 1.52 Mb.
Pdf ko'rish
bet20/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   16   17   18   19   20   21   22   23   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

044.
045.
An array is an object instance. So, when line 1 is executed, the if
condition returns true.
What will be the output of the following code?
int iValue = 10;
int jValue =20;
if(iValue && jValue) { //line 1
System.out.println(True will be printed...”);
}
else {
System.out.println(“False will be printed...”);
}
Answer:
The above code will cause a compilation error at line 1. The && is
the logical AND operator and can only have boolean operands. It
cannot be used with int values.
What will be the output of the following code and why?
System.out.println(“Output is “+ ((10 <
100) ^ (100 > 10)));
Answer:
This code produces the following output:
Output is false
The reason is–
10 < 100 returns true which can be denoted as 1
100 > 10 returns true which can be denoted as 1


046.
047.
The XOR operation is applied on these values. The XOR
operator returns 0 when both values are the same, otherwise
returns 1. Since both values are true, the XOR operator returns 0
which corresponds to false.
What will be output of the following code snippet? Explain
the reasons.
if(!(100 == 1000)) { //line 1
System.out.println(“TRUE gets printed”);
}
else {
System.out.println(“FALSE gets printed”);
}
Answer:
This code produces the following output:
TRUE gets printed
Line 1 checks the condition 100 == 1000, which is false. The if
statement checks the logical NOT(!) of this. The Logical NOT
operator returns the opposite value of its operand. So, it returns a
true. So, the if condition evaluates to a true and the output above
is printed.
Explain the increment and decrement operators.
Answer:
The increment operator is represented by two plus signs. It
increments its operand. The following code demonstrates this:
int i = 10;



Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   16   17   18   19   20   21   22   23   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling