Monday, August 10, 2009

What's the difference between a member variable, and a local variable?

A member variable is a variable that belongs to an object, whereas a local variable belongs to the current scope.

class MoterVehicle{

  String licensePlate = "";     // member variable
  double speed;       = 0.0;    // member variable
  double maxSpeed;    = 123.45; // member variable
 
  boolean isSpeeding() {
    double excess;    // local variable
    excess = this.maxSpeed - this.speed;
    if (excess < 0) return true;
    else return false;
  }

}

No comments: