73.7k views
2 votes
What does the following code display? public class RentalApp { public static void main(String[] args) { Rental r = new Rental(); r. SetNumOfPersons(5); r. AddPerson(); System. Out. Println(r. GetNumOfPersons()); } } public class Rental { private int numOfPersons; public int getNumOfPersons() { return numOfPersons; } public void setNumOfPersons(int numOfPersons) { this. NumOfPersons = numOfPersons; } public void addPerson() { numOfPersons = numOfPersons + 1; } } Group of answer choices 0 1 5 6

1 Answer

4 votes

Answer:

Step-by-step explanation:

The following code will display the number of persons in the Rental object after adding one person to it.

Since the Rental object's numOfPersons field is initialized to 0 by default and the setNumOfPersons method is called to set it to 5, calling the addPerson method will increase the value to 6.

Therefore, the code will display the value of 6.

The output of the code will be:

6

i hope that helped bro

User Vadimtrifonov
by
8.0k points