Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
medium Solved by 5 students

Object Reference Assignment

< Prev
Next >

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

3.9

C

Nothing will be printed. There will be a run-time error.

D

Nothing will be printed. There will be a compile-time error.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1kaisuki12 0m 00s 90
#2winstonhou110711 0m 43s 57
#3zgj0731041711 0m 44s 56
#4ravi.palepu01 1m 01s -71
#5y.seong202712 2m 52s -82
#6bommasam00036 11m 56s -446
Items per page:
10
1 – 6 of 6

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|