Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 2: Using Objects
Start Practice TestPractice Test
About Exam
easy Solved by 4 students

Java Constructor Overloading

Mark
< Prev
Next >

Consider the following class definition.

public class Student {
    private String name;
    private int age;
    private double gpa;
    
    public Student(String n, int a) {
        name = n;
        age = a;
        gpa = 0.0;
    }
    
    public Student(String n, int a, double g) {
        name = n;
        age = a;
        gpa = g;
    }
    
    public String getName() {
        return name;
    }
}

What is printed as a result of executing the following code segment?

Student s1 = new Student("Alice", 16);
Student s2 = new Student("Bob", 17, 3.5);
System.out.println(s1.getName() + " " + s2.getName());
A

Alice Bob

B

null null

C

Student Student

D

Alice 16 Bob 17

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1kaisuki11 0m 00s 100
#2zgj0731041711 3m 08s -88
#3lsj0803092211 39m 12s -2,252
Items per page:
10
1 – 3 of 3

AI Tutor

How can I help?

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