213k views
1 vote
Liza wants to create a variable in her bookEvent class to keep track of the number of tickets booked for an event. This variable should increment every time a new ticket is booked. Which specifier should Liza add before declaring this variable?

1.private. .

User Virgilio
by
7.8k points

1 Answer

4 votes

Final answer:

Liza should use the static specifier for her bookEvent class variable that tracks the number of tickets booked to ensure it is shared by all instances.

Step-by-step explanation:

Liza wants to create a variable in her bookEvent class to keep track of the number of tickets booked for an event. To ensure that this variable correctly increments every time a new ticket is booked, she should use a static specifier. The static keyword will make sure that there is only one instance of this variable shared across all instances of the class, which is essential for accurately counting the number of tickets for the event as a whole, rather than on a per-instance (per-object) basis. She may also want to declare this variable as private to encapsulate the data and control its access, often providing a public method to manipulate it safely.

In order to keep track of the number of tickets booked for an event, Liza should use the private specifier before declaring the variable. This specifier restricts access to the variable, allowing it to only be accessed and modified by methods within the same class.

User Piercy
by
8.0k points