nerdexam
Oracle

1Z0-805 · Question #72

Given the code fragment: public class App { public static void main (String [] args) { path path = paths.get("C\\educations\\institute\\student\\report.txt"); system.out.printIn("getName(0): %s"…

The correct answer is D. getName(0): education. The getName(int index) method returns a name element of this path as a Path object. The subpath(int beginIndex, int endIndex) method returns a relative Path that is a subsequence of the name elements of this path.

Java I/O Fundamentals

Question

Given the code fragment:

public class App { public static void main (String [] args) { path path = paths.get("C\educations\institute\student\report.txt"); system.out.printIn("getName(0): %s", path.getName(0)); system.out.prinIn("subpath(0, 2): %s" path.subpath(0, 2)); } } What is the result?

Options

  • AgetName (0): C:\
  • BgetName (0): C:\
  • CgetName(0): education
  • DgetName(0): education
  • EgetName(0): report.txt

How the community answered

(25 responses)
  • A
    4% (1)
  • C
    8% (2)
  • D
    72% (18)
  • E
    16% (4)

Explanation

The getName(int index) method returns a name element of this path as a Path object. The subpath(int beginIndex, int endIndex) method returns a relative Path that is a subsequence of the name elements of this path.

Topics

#Path API#NIO.2#getName#subpath

Community Discussion

No community discussion yet for this question.

Full 1Z0-805 Practice