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

Object Reference Mutation

Mark
< Prev
Next >

An object is passed as a parameter to a method, allowing the method to change the internal state of the original object.

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

public class QuestionTrace {

    public static void main(String[] args) {
        Data d = new Data();
        d.val = 5;
        modify(d);
        System.out.print(d.val);
    }

    public static void modify(Data obj) {
        obj.val = obj.val * 3;
    }
}

class Data {

    public int val;
}
A

3

B

5

C

8

D

15

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|