Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 3: Class Creation
Start Practice TestPractice Test
About Exam
hard

Lamp State Independence

Mark
< Prev
Next >

Two separate Lamp objects demonstrate how instance fields maintain unique states independently of other instances.

What is printed when the following Java program is compiled and run?

public class QuestionTrace {

    public static void main(String[] args) {
        Lamp l1 = new Lamp();
        Lamp l2 = new Lamp();
        l1.toggle();
        System.out.print(l1.isOn() + "" + l2.isOn());
    }
}

class Lamp {

    private boolean on;

    public void toggle() {
        on = !on;
    }

    public boolean isOn() {
        return on;
    }
}
A

truetrue

B

falsetrue

C

truefalse

D

falsefalse

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

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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