Keyword super and its usage

The keyword super represents the parent class object. To demonstrate its usage, let's create a programming model of a vehicle, a truck, and a car. Let's start with a vehicle. The class that models it calculates the speed of the vehicle it can reach in a specified period of time, in seconds. It looks as follows:

public class Vehicle {  private int weightPounds, horsePower;  public Vehicle(int weightPounds, int horsePower) {    this.weightPounds = weightPounds;    this.horsePower = horsePower;  }  protected int getWeightPounds(){ return this.weightPounds; }  protected double getSpeedMph(double timeSec, int weightPounds){    double v =         2.0 * this.horsePower * 746 * timeSec * 32.174 / weightPounds;    return Math.round(Math.sqrt

Get Introduction to Programming now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.