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 3 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: 18

B

Name: Alice, Age: 20

C

Name: Alice, Age: 21

D

Name: null, Age: 0

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
#1sgarv251314 0m 00s 70
#2kaisuki14 0m 00s 70
#3bommasam00003 1m 29s -119
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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