title: How do I share methods with instance variables in a superclass?
body: <p>I have an abstract class called Car. Then I have two subclasses, Ford and Dodge which both extend Car. Each of these subclasses have a method called move(). The code in this method is identical for Ford and Dodge, so naturally my instinct was to throw this method implementation into the Car superclass so I don't have to have the same code twice in both my subclasses, i.e. get duplicated code, and just have this method written out once in code inside the superclass, and each subclass can call it when it needs to.</p>
  
  <p>Now here's my...thing: Inside the move methods in each subclass, instance variables from each subclass are being manipulated. So you see, even though the code is identical, what is happening in each move()-method is depending on the state of that specific subclass's instance variables. Like this:</p>
  
  <pre><code>abstract class Car {
  
    // I want to put move()-method in here and erase it from subclasses
  }
  
  
  class Ford extends Car {
  
      private int rpm;
  
      public void move(){
  
      dosomestuff + rpm // value of rpm being used here is unique to Ford
  
       }
  }
  
   class Dodge extends Car {
  
      private int rpm;
  
      public void move(){
  
      dosomestuff + rpm // value of rpm being used here is unique to Dodge
  
       }
  }
  </code></pre>
  
  <p>I want to have it like this, and call move() in the superclass from each subclass using the subclasses instance variables:</p>
  
  <pre><code>abstract class Car {
  
    move(){
      // do stuff that is identical to Ford and Dodge but
      //  dependent on different instance variables
      }
  }
  
  
  class Ford extends Car {
  
      private int rpm;
  }
  
   class Dodge extends Car {
  
      private int rpm;
  
  }
  </code></pre>
  
  <p>Should I create variables inside the superclass Car? But that is what I am having problem wrapping my head around, because I know an abstract class cannot be instantiated! So if I were to pass the rpm-variable in this case as a parameter in the move() method like move(rpm), while I am having the implementation for move() only inside the Car class, I would have to return the rpm-variable to get its manipulated value back. This works, for once instance variable form a subclass. The problem is, the move-methods depend on several different kinds of variables. So I would have to return several variables back to the subclass each time but I am not sure how to do that.</p>
  
  <p>I am confused. How can I condense this "duplicated code" inside my subclasses into the superclass Car and still be able to manipulate instance variables from the different subclasses inheriting from the Car class? Do I pass them as parameters and return them? Do I do something with get-set methods? I am so unsure...</p>