title: Returning data from a superclass in java
body: <p>I have read about superclasses, abstraction etc. I understand most of the general ideas.
  I have 3 classes right now (main, superclass, subclass)</p>
  
  <p>First class: Grabs user miles and gallons for type of car, sends data to subclass. Subclass sets the data to variables.</p>
  
  <p>I am trying to figure out a way to print the miles per gallon for the car. This calculation method lies within the superclass, but I can't find a way to print the method.
  Here is my code:</p>
  
  <p>Main</p>
  
  <hr>
  
  <pre><code>import java.util.Scanner;
  public class StartingPoint {
  
      public static void main (String[]args)
      {
          Scanner input = new Scanner(System.in); //Get user input
  
          Mercedes mCar = new Mercedes(); //Accesses subclass of the Car superclass (Mercedes)
          Toyota tCar = new Toyota(); //Accesses subclass of the Car superclass (Toyota)
  
          System.out.println("Do you own a mercedes or a toyota?"); //Get car type
  
          String carName = input.nextLine();
  
          if (carName.charAt(0) == 'm' || carName.charAt(0) == 'M')
          {
              System.out.println("How many miles have you travelled?");
              double miles = input.nextDouble();
  
              System.out.println("How many gallons have you used?");
              double gallons = input.nextDouble();
  
              mCar.setGallons(gallons);
              mCar.setMiles(miles);
  
          }
  
          else if (carName.charAt(0) == 't' || carName.charAt(0) == 'T')
          {
               //NOT CODED YET
          }
  
          else 
          {
              System.out.println("Not a valid car name for the system...");
          }
  
  
  
  
  
      }
  
  }
  </code></pre>
  
  <p>Super Class</p>
  
  <hr>
  
  <pre><code>public abstract class Car {
  
      public double calcMPG(double miles, double gallons)
      {
          return (miles/gallons);
      }
  }
  </code></pre>
  
  <p>Subclass of Superclass (Car)</p>
  
  <hr>
  
  <pre><code>public class Mercedes extends Car {
  
      private double miles;
      private double gallons;
  
      public Mercedes()
      {
          miles = 0;
          gallons = 0;
      }
  
      public void setMiles(double inputMiles)
      {
          miles = inputMiles;
      }
  
      public void setGallons(double inputGallons)
      {
          gallons = inputGallons;
      }
  
  
  
  
  
  
  
  }
  </code></pre>