Constructor and Instance Variable Initialization
Consider the following class definition and object instantiation.
public class Student {
private String name;
private int grade;
private double gpa;
public Student(String studentName, int studentGrade) {
name = studentName;
grade = studentGrade;
gpa = 0.0;
}
}
Student s = new Student("Alice", 11);
What are the values of the instance variables for the Student object s after the code segment has been executed?
A
name = “Alice”, grade = 11, gpa = 0.0
B
name = “studentName”, grade = studentGrade, gpa = 0.0
C
name = “Alice”, grade = 11, gpa = null
D
name = null, grade = 0, gpa = 0.0
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | Ishaan.m.kurup | 2 | 3 | 0m 00s | 190 |
| #2 | songqiuhui2012 | 2 | 2 | 0m 57s | 143 |
| #3 | sailajavadlamani33 | 1 | 1 | 0m 00s | 100 |
| #4 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #5 | dinhhoa | 1 | 2 | 0m 00s | 90 |
| #6 | y.seong2027 | 1 | 1 | 0m 32s | 68 |
| #7 | psak12 | 1 | 1 | 0m 47s | 53 |
| #8 | suhanakochhar006 | 1 | 1 | 3m 36s | -116 |
APFIVE