Question: What are the errors in this code? //1. //Filename: CarbonFootprintTest.java //The file tests the Car class and CarbonFootprint class public class CarbonFootprintTest { public static
What are the errors in this code?
//1.
//Filename: CarbonFootprintTest.java //The file tests the Car class and CarbonFootprint class public class CarbonFootprintTest { public static void main (String [] args) {
CarbonFootprint[] obj = new CarbonFootprint[2]; obj[0] = new CarbonFootprint(20); obj[1] = new Car(30);
System.out.println("Carbon Foot Print for each item (lbs): "); //additional info for to give general idea of program for (CarbonFootprint test: obj) test.getCarbonFootprint();
}//end main method }//end class
//2. Filename: CarbonFootprint.java It only include
s one abstract method public class CarbonFootprint { //returns the carbon footprint of an object public void GetCarbonFootprint();
}//end interface
//3. Filename: Car.java public class Car extends CarbonFootprint { private double gallons; public Car( double g ){ gallons = g; } // end Car constructor // one gallon of gas yields 20 pounds of CO2 public abstract void GetCarbonFootprint(){ System.out.printf( "Car that has used %.2f gallons of gas: %.2f ", gallons, gallons * 20 ); } // end function GetCarbonFootprint } // end class Car
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
