Skip to content

Instantly share code, notes, and snippets.

@Aroueterra
Last active May 20, 2021 04:55
Show Gist options
  • Save Aroueterra/e3e6dd3965fcb7c8cb7d05a8ac5288e9 to your computer and use it in GitHub Desktop.
Save Aroueterra/e3e6dd3965fcb7c8cb7d05a8ac5288e9 to your computer and use it in GitHub Desktop.
class TestClass {
private String color;
public TestClass(String c) {
color = c;
}
// In getter, returnColor should return String
public void returnColor() {
return color;
}
// No return statement error (setter should actually be void) + newColor should not be a method call
public String changeColor(String newColor) {
color = newColor();
}
}
public class LabQuestion {
public static void main(String[] args) {
TestClass myObject = new TestClass("red");
myObject.changeColor("blue");
System.out.println(myObject.returnColor());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment