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
easy Solved by 10 students

Constructor and Instance Variable Initialization

< Prev
Next >

Develop code to declare instance variables for the attributes to be initialized in the body of the constructors of a class.

Consider the following code segment:

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 after the constructor executes?

A

name = null, grade = 0, gpa = 0.0

B

name = “studentName”, grade = studentGrade, gpa = 0.0

C

name = “Alice”, grade = 11, gpa = 0.0

D

name = “Alice”, grade = 11, gpa = null

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
#1Ishaan.m.kurup23 0m 00s 190
#2songqiuhui201222 0m 57s 143
#3sgarv251311 0m 00s 100
#4sailajavadlamani3311 0m 00s 100
#5dinhhoa12 0m 00s 90
#6y.seong202711 0m 32s 68
#7psak1211 0m 47s 53
#8varunrajaram111 1m 25s 15
#9suhanakochhar00611 3m 36s -116
#10chunxiangxu.cxu01 2m 16s -146
Items per page:
10
1 – 10 of 11

AI Tutor

How can I help?

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