Question: Whats wrong with replacing the println statement in Figure 14.2s main method with these two statements? String description = car.toString(); System.out.println(description); Figure 14.2 /*************** *********
What’s wrong with replacing the println statement in Figure 14.2’s main method with these two statements?
String description = car.toString();
System.out.println(description);
Figure 14.2

/*************** ********* * Car2.java *Dean & Dean * * This instantiates a car and displays its properties. **** public class Car2 { private String make; // car's make private int year; private String color; // car's color //********** this.make = make; this.year = year: this.color = color; } // end Car2 constructor //*********** public Car2 (String make, int year, String color) ( @Override *********************** public String toString() ( // car's listed year } // end toString. //********** return "make = "+make+", year = ", color="+ color; } // end main } // end class Car2 ******/ public static void main(String[] args) ( ********** ********************** + year + ************** Car2 car= new Car2("Honda", "2020", "silver"); System.out.println(car); This overrides the Object class's toString method.
Step by Step Solution
3.39 Rating (152 Votes )
There are 3 Steps involved in it
Nothing Its just a ... View full answer
Get step-by-step solutions from verified subject matter experts
