Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
medium Solved by 3 students

Inheritance and Instance Variable Modification

< Prev
Next >

Consider the following code segment. When this code is executed, how many times will the while loop in the countWhile method iterate?

class BaseCounter2 {
    int limit = 8;
    public void countWhile() {
        int i = 0;
        while(i < limit) {
            System.out.print(i + " ");
            i++;
        }
    }
}

class ChildCounter2 extends BaseCounter2 {
    public ChildCounter2() {
        limit = 5;
    }
}

public class Main {
    public static void main(String[] args) {
        ChildCounter2 cc = new ChildCounter2();
        cc.countWhile();
    }
}
A

5

B

6

C

8

D

4

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1kaisuki22 0m 00s 200
#2y.seong202701 0m 28s -38
#3suhanakochhar00613 39m 36s -2,296
#4psak1212 1h 41m -5,997
Items per page:
10
1 – 4 of 4
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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