title: Java classes inheritance
body: <p><a href="http://java.sun.com/docs/books/tutorial/java/concepts/inheritance.html" rel="nofollow noreferrer">Here</a>, it  says that:</p>
  
  <blockquote>
    <p>This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. This makes code for your subclasses easy to read. However, you must take care to properly document the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass.</p>
  </blockquote>
  
  <p>However in my code the inheritance doesn't work properly, probably due to a flaw in my code?</p>
  
  <pre><code>package java1;
  
  class bicycle {
      int speed = 0;
      int gear = 1;
  
      void accelerate(int incr) {
          speed = speed + incr;
      }
  
      void decelerate(int incr) {
          speed = speed - incr;
      }
  
      void changeGear(int val) {
          gear = val;
      }
  
      void printInfo() {
          System.out.println("Speed: " + speed + " Gear: " + gear);
      }
  }
  
  class mountainbike extends bicycle {
      int speed = 10;
  }
  
  public class Main {
  
      public static void main(String[] args) {
  
          mountainbike mb1 = new mountainbike();
  
          mb1.accelerate(20);
          mb1.accelerate(10);
  
          mb1.printInfo();
  
      }
  
  }
  </code></pre>
  
  <p>The mountainbike class should inherit all the characteristics of the bicycle class, right? I added a unique property which is <code>int speed = 10</code>, so starting speed should be 10. However on running the compiler treats starting speed as 0.</p>
  
  <p>Any ideas?</p>