Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
easy

While Loop Iteration Count

Mark
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|