While Loop Iteration Count
Consider the following classes. When the main method is executed, how many times will the body of the while loop in whileLoopMethod be executed?
class BaseCounter {
public void whileLoopMethod() {
int count = 0;
int i = 2;
while (i < 10) {
count++;
i += 2;
}
System.out.println(count);
}
}
class DerivedCounter extends BaseCounter { }
public class Main {
public static void main(String[] args) {
DerivedCounter dc = new DerivedCounter();
dc.whileLoopMethod();
}
}
A
5
B
3
C
6
D
4
Question Leaderboard
Not enough data yet to show leaderboard.
