Return to site

☕🎓JAVA CERTIFICATION QUESTION: subpathAdd a Blog Post Title

· ocp,java

Given:

What is the output?

  • a
  • b
  • c
  • a/b
  • b/c
  • Compilation fails

#java #certificationquestion #ocp

Answer: b

According to Javadoc:

Path subpath(int beginIndex,

int endIndex)

Returns a relative Path that is a subsequence of the name elements of this path.

The beginIndex and endIndex parameters specify the subsequence of name elements.

The name that is closest to the root in the directory hierarchy has index 0.

The name that is farthest from the root has index count-1.

The returned Path object has the name elements that begin at beginIndex and extend to the element at index endIndex-1.

This means a has index 0, b index 1, and c index 2.

This means also that subpath take between 1 inclusive and 2 exclusive so it takes only b.