Java OCA OCP Practice Question 324

Question

Given a partial directory tree:

dir x - |
..........| - dir y
..........| - file a

In what order can the following methods be called if walking the directory tree from x?

Choose all that apply.

I:   preVisitDirectory x
II:  preVisitDirectory x/y
III: postVisitDirectory x/y
IV:  postVisitDirectory x
V:   visitFile x/a
  • A. I, II, III, IV, V
  • B. I, II, III, V, IV
  • C. I, V, II, III, IV
  • D. I, V, II, IV, III
  • E. V, I, II, III, IV
  • F. V, I, II, VI, III


B and C are correct because file visitor does a depth-first search.

Note

When files and directories are at the same level of the file tree, they can be visited in either order.

Therefore, "y" and "a" could be reversed.

All of the subdirectories and files are visited before postVisit is called on the directory.




PreviousNext

Related