Class Constructor and Getter Method
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
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 2 | 2 | 0m 00s | 200 |
| #2 | bommasam000 | 2 | 3 | 0m 41s | 149 |
| #3 | songqiuhui2012 | 0 | 1 | 0m 02s | -12 |
| #4 | y.seong2027 | 1 | 1 | 5m 09s | -209 |
Items per page:
10
1 – 4 of 4
