| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
Share
About Exam
medium Solved by 2 students
Variable Shadowing in a Java Class
< Prev
Next >

Consider the following class definition. What is printed when the subsequent code segment is executed?

public class Student {
    private String name;
    private int age;
    
    public Student(String name, int age) {
        name = name;
        age = age;
    }
    
    public void setAge(int age) {
        age = age + 1;
    }
    
    public void printInfo() {
        System.out.println("Name: " + name + ", Age: " + age);
    }
}
Student s = new Student("Alice", 18);
s.setAge(20);
s.printInfo();
A

Name: Alice, Age: 20

B

Name: null, Age: 0

C

Name: Alice, Age: 18

D

Name: Alice, Age: 21

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1sgarv251314 0m 00s 70
#2kaisuki14 0m 00s 70
#3bommasam00003 1m 29s -119
Items per page:
10
1 – 3 of 3

AI Tutor

How can I help?

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