Java OCA OCP Practice Question 2565

Question

Consider the following program:

import java.nio.file.*;

class Main {
       public static void main(String []args) {
                Path aPath = Paths.get("C:\\WINDOWS\\system32\\config\\systemprofile\\Start Menu\\Programs\\Accessories\\Entertainment\\Windows Media Player");
               System.out.println(aPath.subpath(3, 4));
       }
}

Which one of the following options is correct?

  • a)This program prints the following: config\systemprofile.
  • b)This program prints the following: config.
  • c)This program prints the following: systemprofile.
  • d)This program prints the following: system32\config.
  • e)This program throws an IllegalArgumentException.


c)

Note

Here is the description of the subpath method:

The subpath(int beginIndex, int endIndex) method returns a Path object.

The returned Path object has names that begin at beginIndex till the element at index endIndex - 1.

In other words, beginIndex is inclusive of the name in that index and exclusive of the name in endIndex.

This method may throw an IllegalArgumentException if beginIndex is >= number of elements, or endIndex <= beginIndex, or endIndex is > number of elements.

In this program, the index starts with WINDOWS, at index 0.

The given beginIndex is 3, so it is the subpath systemprofile, and it is exclusive of the endIndex with value4.




PreviousNext

Related