
Concept explainers
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
public class Vehicle
{
public Vehicle()
{
System.out.println (“You should not operate this vehicle under the”);
System.out.println(“influence of alcohol!”);
}
}

Want to see the full answer?
Check out a sample textbook solution
Chapter 6 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
Additional Engineering Textbook Solutions
Fluid Mechanics: Fundamentals and Applications
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Electric Circuits. (11th Edition)
Concepts Of Programming Languages
Mechanics of Materials (10th Edition)