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:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.