title: Child class Changing a protected variable from a Parent class in Java
body: <p>I know that it is bad design to have a protected variable in a parent class because all child classes can change that value. However, I was trying to test it out but I am doing something wrong here. It's telling me that cannot find symbol <code>speed = 999999;</code> in Truck class. I thought the child class has access to the protected variable <code>speed</code> in parent class.</p>
  
  <pre><code>public class Vehicle {
      protected double speed;
      protected double maxSpeed;
  
      public Vehicle(double speed, double maxSpeedIn) throws InvalidDataException{
          setSpeed(speed);
          maxSpeed = maxSpeedIn;
      }
  
      public void setSpeed(double s) throws InvalidDataException {
          if (s &lt; 0.0) {
              throw new InvalidDataException("Negative speed is not valid" );
          }
          if (s &gt; maxSpeed) {
              throw new InvalidDataException("Speed cannot exceed maximum spped:");
          }
          speed = s;
      }
  
  
  }
  
  public class Truck extends Vehicle {
  
      public Truck(double speedin, double maxSpeedin) throws InvalidDataException {
          super(speedin,maxSpeedin);
      }
  
      speed = 999999;
  
  }
  </code></pre>