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


Download 1.52 Mb.
Pdf ko'rish
bet24/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   20   21   22   23   24   25   26   27   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

Answer:
Output: c b c a b c
Since caseVal is declared as a final variable, it is evaluated at
compile time. When iterNo = 0, the 3rd case statement is
true, so it prints c. In the second iteration, iterVal becomes 1,
so the second case statement is true so it prints b. Since there is
no break statement after the second case, the third case
statement is also executed which prints c. During the third
iteration, the first case is true and so a is printed. This is followed
by b and c since there is no break after case.


056.
057.
What happens when you execute the code below? If it
compiles, what will be the output?
int iValue1 = 100;
int iValue2 = 200;
boolean isTrue() {
return true;
}
if(((iValue1 > iValue2) && (iValue2 < 50))
|| isTrue()) { //Line 1
System.out.println(“This is True”);
}
else {
System.out.println(“This is False”);
}
Answer:
The code compiles fine and displays the following output:
This is True
The if statement at Line 1 uses an OR operation. An OR
operation returns true when any one of its operands is true. Since
the isTrue() method returns a true, the if statement will return
a true. So irrespective of the result of the AND operation, the
expression within the If statement returns a true.
What is the use of “break” and “continue” statements?
Answer:
The break keyword can be used within a loop. When the break
statement is encountered, the loop is immediately terminated and


058.
059.
control is transferred outside the loop.
The continue keyword can also be used within a loop. It is used
to stop executing the next statement in the loop for the current
iteration and transfer control to the start of the loop.

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   20   21   22   23   24   25   26   27   ...   171




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