Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
medium Solved by 3 students

Object Reference Assignment and Method Calls

< Prev
Next >

Just before exiting this program, what are the object values of x, y, and a, respectively?

This question refers to the following class:

public class IntObject
{
    private int num;
    public IntObject() // default constructor
    { num = 0; }
    public IntObject(int n) // constructor
    { num = n; }
    public void increment() // increment by 1
    { num++; }
}

Here is a client program that uses this class:

public class IntObjectTest
{
    public static IntObject someMethod(IntObject obj)
    {
        IntObject ans = obj;
        ans.increment();
        return ans;
    }

    public static void main(String[] args)
    {
        IntObject x = new IntObject(2);
        IntObject y = new IntObject(7);
        IntObject a = y;
        x = someMethod(y);
        a = someMethod(x);
    }
}

Just before exiting this program, what are the object values of x, y, and a, respectively?

A

2, 8, 9

B

2, 9, 9

C

3, 8, 9

D

9, 9, 9

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
#1chunxiangxu.cxu56 1m 07s 423
#2sailajavadlamani3301 0m 00s -10
#3y.seong202712 7m 51s -381
#4suhanakochhar00616 13m 42s -772
Items per page:
10
1 – 4 of 4

AI Tutor

How can I help?

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