What is the result?

Given:

import java.io.File;

import java.nio.file.Path;

public class Test12 {

static String displayDetails(String path, int location) {

Path p = new File(path).toPath();

String name = p.getName(location).toString();

return name;

}

public static void main(String[] args) {

String path = “project//doc//index.html”;

String result = displayDetails(path,2);

System.out.print(result);

}

}

What is the result?

Given:

import java.io.File;

import java.nio.file.Path;

public class Test12 {

static String displayDetails(String path, int location) {

Path p = new File(path).toPath();

String name = p.getName(location).toString();

return name;

}

public static void main(String[] args) {

String path = “project//doc//index.html”;

String result = displayDetails(path,2);

System.out.print(result);

}

}

What is the result?

A.
doc

B.
index.html

C.
an IllegalArgumentException is thrown at runtime.

D.
An InvalidPthException is thrown at runtime.

E.
Compilation fails.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


surfo

surfo

The answer is B