130k views
0 votes
Given the node class (partially shown below), select a statement to complete the recursive method "descendants," which is designed to return the number of descendants of a node:

a) This.parent = parent;
b) return 0;
c) count++;
d) int count = 0;

User MattDavis
by
8.3k points

1 Answer

2 votes

Final answer:

The correct statement to complete the recursive method "descendants" is c) count++;

Step-by-step explanation:

The correct statement to complete the recursive method "descendants" is c) count++;. This statement will increment the count variable by 1 each time the method is called, indicating that a descendant has been found.

The count variable should be declared outside of the method as a class variable, so it can be accessed and updated by the recursive calls.

User Pleonasmik
by
8.2k points