Part1)Write a small program which uses dynamic binding. In your comments explain which statement(s) is doing the dynamic binding. Submit your program as an attached .java file and post a screen shot...

1 answer below »
Part1)Write a small program which uses dynamic binding. In your comments explain which statement(s) is doing the dynamic binding. Submit your program as an attached .java file and post a screen shot to show that you have been able to successfully run that program. Make sure you submission adheres to the SubmissionRequirements document.
Answered 1 days AfterFeb 10, 2021

Answer To: Part1)Write a small program which uses dynamic binding. In your comments explain which statement(s)...

Sayed Shad Ahmad answered on Feb 11 2021
158 Votes
Solution/DynamicBinding.java
Solution/DynamicBinding.java
//Class Vehicle
class Vehicle
{
    //Data Members for Vehicle class
    private String name;
    private St
ring type;
    private double mileage;

    //Constructor
    public Vehicle(String name, String type, double mileage)
    {
        this.name = name;
        this.type = type;
        this.mileage = mileage;
    }

    //Getter methods for Vehicle class
    public String getName()
    {
        return name;
    }
    public String getType()
    {
        return type;
    }
    public double getMileage()
    {
        return mileage;
    }
    //Method toString to return String representation of Vehicle
    public String toString()
    {
        String info = this.name + " is a " + this.type + " with a mileage of " +
                        String.format("%.1f", this.mileage) + " mpg.";
        return info;
    }
}
//Class Car derived from base class Vehicle
class Car extends Vehicle
{
    //Data Members for Car class
    private int noOfSeats;
    private int topSpeed;
    //Constructor for Car class
    public Car(String name, double mileage, int noOfSeats, int topSpeed)
    {
        super(name, "car", mileage);
        this.noOfSeats = noOfSeats;
        this.topSpeed = topSpeed;
    }
    @Override
    //Overridden method toString to return String representation of Car
    public String toString() 
    {
        String info = "It is a " + this.noOfSeats +
                        " seater car with a top speed of " +
                        this.topSpeed + " mph.";
        return super.toString() + "\n" + info;
    }
}
//Class Bike derived from base class Vehicle
c...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here