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
medium

Static and Instance Interaction

Mark
< Prev
Next >

A program uses a static utility method to perform a calculation that modifies the instance state of an object.

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

public class QuestionTrace {

    public static void main(String[] args) {
        Calculator c = new Calculator();
        c.set(Calculator.calculate(5));
        System.out.print(c.getResult());
    }
}

class Calculator {

    private int res;

    public static int calculate(int x) {
        return x * 2;
    }

    public void set(int val) {
        res = val;
    }

    public int getResult() {
        return res;
    }
}
A

25

B

10

C

5

D

0

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|