Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

AP CSA Question of the Day May 29, 2025

Reference
  1. Incorrect Correct No Answer was selected Invalid Answer

    Which of the following correctly declares a constructor for the class Device that initializes both name and status?

    public class Device
    {
        private String name;
        private boolean status;
    
        // Constructor goes here
    }
    Java

    A constructor must:

    • Have the same name as the class (Device)
    • Have no return type
    • Avoid using the same parameter names as instance variables to prevent shadowing