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
Given an instance of the Song class called song, what is the proper way to set the length after it has been instantiated?
Song
song
length
public class Song { private String title; private String artist; private double length; public double getLength() { return this.length; } public Song(String title, String artist, double length) { this.title = title; this.artist = artist; this.length = length; } }
song.length = 3.5;
song.getLength() = 3.5;
song.getLength(3.5);
song.setLength(3.5);
You cannot set the length, since length is private and there is no setter method.