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

Constructor Shadowing

Mark
< Prev
Next >

An Item class defines a private field and initializes it using a constructor parameter with the same name.

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

public class QuestionTrace {

    public static void main(String[] args) {
        Item i = new Item(5);
        System.out.print(i.getValue());
    }
}

class Item {

    private int value;

    public Item(int value) {
        this.value = value + 10;
    }

    public int getValue() {
        return value;
    }
}
A

15

B

5

C

0

D

10

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|