The following class displays a disclaimer every time an instance is created using the default constructor. However, we would like the disclaimer to appear only once when the very first Vehicle object is created. Any future Vehicle objects that are created should display no disclaimer. Modify the code to use a static boolean variable that is initialized to false when it is defined. Once the disclaimer is displayed the variable should be set to true, and an if statement added around the display so the disclaimer is only output if the variable has the value false. This should force the program to display the disclaimer only once. Add a main method and test code to verify that the disclaimer is only displayed once.
public class Vehicle{ public Vehicle() { System.out.println(“ You should not operate this vehicle under the”); System.out.println(“influence of alcohol!”); }}
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.