Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
Which of the following correctly declares a constructor for the class Device that initializes both name and status?
Device
name
status
public class Device { private String name; private boolean status; // Constructor goes here }
public void Device(String input, boolean s) { name = input; status = s; }
public Device(String name, boolean status) { name = name; status = status; }
public Device(String input, boolean s) { name = input; status = s; }
Device(String input, boolean s) { input = name; s = status; }
A constructor must: