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
easy Solved by 3 students

Class Constructor and Getter Method

Mark
< Prev
Next >

Consider the following class definitions. What is printed as a result of executing the main method of the TestPerson class?

public class Person {
    private String name;
    public Person(String name) {
        this.name = name;
    }
    public String getName() {
        return this.name;
    }
}

public class TestPerson {
   public static void main(String[] args) {
       Person p = new Person("Alice");
       System.out.println(p.getName());
   }
}
A

Alice

B

The object’s memory reference

C

Compilation Error

D

null

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1kaisuki22 0m 00s 200
#2bommasam00023 0m 41s 149
#3songqiuhui201201 0m 02s -12
#4y.seong202711 5m 09s -209
Items per page:
10
1 – 4 of 4

AI Tutor

How can I help?

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