Java Java Objects Harnessing the Power of Objects Overload Methods

Adam Meikle
Adam Meikle
3,053 Points

Trying to understand how to call a method within a new method and set a default

Trying to understand how to call a method within a new method and set a default

GoKart.java
class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private int barCount;
  private int lapsDriven;

  public GoKart(String color) {
    this.color = color;
  }

  public String getColor() {
    return color;
  }
  public void charge() {
    barCount = MAX_BARS;
  }

  public boolean isBatteryEmpty() {
    return barCount == 0;
  }

  public boolean isFullyCharged() {
    return MAX_BARS == barCount;
  }

  public void drive(int lapsToGo) {
    lapsDriven+= lapsToGo;
    barCount-= barCount;
  }

  public void drive() {
   int drive = 1
    }

}

1 Answer

Steven Parker
Steven Parker
201,997 Points

A call is just the method name followed by parentheses, and you can pass your "default" value as the argument.

    drive(1);
Steven Parker
Steven Parker
201,997 Points

Adam Meikle — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!