| preferred AP College board partner for AP classes
Login
 
Register
AP Computer Science A/Unit 9: Inheritance
Start Practice Test
Share
Inheritance and Instance Variable Modification
< Prev
Next >

With the ChildCounter2 class modifying the limit, how many iterations does the while-loop in countWhile() execute?

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

4

C

6

D

8

Check Answer
APFIVE © 2020.
Email: [email protected]|Privacy Policy