Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Hard
Question 17
class AcademicRecord {
String studentName;
int score;
AcademicRecord(String studentName, int score) {
this.studentName = studentName;
this.score = score;
}
}
public class ScoreTest {
public static void main(String[] args) {
AcademicRecord record = new AcademicRecord("Ahmed", 25);
int initialScore = 25;
updateScore(record, initialScore);
System.out.println(initialScore + "-" + record.score);
}
private static void updateScore(AcademicRecord record, int score) {
score += 10;
record.score += score;
}
}
What will be the result of executing the ScoreTest class?
-
A
“25-35”
-
B
"25-60"
-
C
"35-60”
-
D
"60-60”
Reveal correct answer
Correct answer: B
Explanation
The updateScore method modifies the score of the AcademicRecord object by adding the updated local score (35) to the original score (25), resulting in 60. The initialScore variable remains unchanged.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
