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.

/*************** ********* * 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

1 Expert Approved Answer
Step: 1 Unlock

Nothing Its just a ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction To Programming With Java A Problem Solving Approach Questions!