| 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 6 students
Java Constructor Overloading
< Prev
Next >

Identify, using its signature, the correct constructor being called.

Consider the following class:

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 when the following code executes?

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

Alice 16 Bob 17

B

null null

C

Student Student

D

Alice Bob

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2zgj0731041711 3m 08s -88
#3lsj0803092211 39m 12s -2,252
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: [email protected]|Privacy Policy