public class Student {
private String name;
public Student(String n) { name = n; }
public String getName() { return name; }
}
// ...
Student s = new Student("Ana");
System.out.println(s.getName());What is printed?
- A
Compile-time error
- B
null
- C
name
- Dcheck_circle
Ana
Explanation
The accessor method getName returns the instance variable name, which was set to "Ana" by the constructor.