LearnFrenzy
Sign in Take a free test

File Handling, IO and NIO · Find the Error · Question 3

Error: creating a Path with new Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
import java.nio.file.Path;

public class Main {
    public static void main(String[] args) {
        Path p = new Path("data.txt");
        System.out.println(p);
    }
}
  • A data.txt must be absolute
  • B Path is an interface and cannot be instantiated; use Path.of("data.txt") (or Paths.get) Correct
  • C Path needs two arguments
  • D println cannot print paths
Correct Answer: Option B

javac: "Path is abstract; cannot be instantiated".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links