Object Reference Assignment
Refer to the following class:
public class Student
{
private String name;
private double gpa;
public Student(String newName, double newGPA)
{
name = newName;
gpa = newGpa;
}
public String getName()
{
return name;
}
/* Additional methods not shown */
}
Consider the following code segment.
Student s1 = new Student("Brody Kai", 3.9);
Student s2 = new Student("Charlie Cole", 3.2);
s2 = s1;
s2.setGpa(4.0);
System.out.println(s1.getGpa());
What is printed as a result of executing the code segment?
A
4.0
B
Nothing will be printed. There will be a run-time error.
C
Nothing will be printed. There will be a compile-time error.
D
3.9
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #2 | winstonhou1107 | 1 | 1 | 0m 43s | 57 |
| #3 | ravi.palepu | 0 | 1 | 1m 01s | -71 |
| #4 | y.seong2027 | 1 | 2 | 2m 52s | -82 |
| #5 | bommasam000 | 3 | 6 | 11m 56s | -446 |
Items per page:
10
1 – 5 of 5
APFIVE