public class Person {
private String name;
public Person(String name) {
name = name;
}
public String getName() { return name; }
}
// ...
Person p = new Person("Bo");
System.out.println(p.getName());What is printed?
- Acheck_circle
null
- B
Bo
- C
name
- D
Compile-time error
Explanation
Without this.name = name the assignment only sets the parameter to itself; the instance variable name remains its default null.