OCA Wrong Answer - Test 5 Question 33

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
macetini
Posts: 2
Joined: Wed Nov 13, 2024 11:20 am
Contact:

OCA Wrong Answer - Test 5 Question 33

Post by macetini »

While answering questions for OCP cert came across this question:

Code: Select all

What will the following code fragment print?

        Path p1 = Paths.get("c:\\personal\\.\\photos\\..\\readme.txt");
        Path p2 = Paths.get("c:\\personal\\index.html");
        Path p3 = p1.relativize(p2);
        System.out.println(p3);
The correct answer was :

Code: Select all

..\..\..\..\index.html
But on my machine (eclipse Ide, jdk13) i get this:

Code: Select all

..\index.html
Makes sense to me. Am I doing something wrong?

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: OCA Wrong Answer - Test 5 Question 33

Post by admin »

This question is not from OCA. It is from OCP.
Are you using OCP 8 question bank?

1. Java >=11 normalizes paths before computing relativize. Since you are using Java 13, you are getting a different answer.
2. As per JavaDoc of the relativize method:
Where both paths have a root component then it is implementation dependent if a relative path can be constructed.
Depending on which version of the exam you are studying for the answer would be different. The explanation in the OCP java 11 question bank notes this point. But if you are using OCP 8 question bank then the given answer is correct.

macetini
Posts: 2
Joined: Wed Nov 13, 2024 11:20 am
Contact:

Re: OCA Wrong Answer - Test 5 Question 33

Post by macetini »

Yes, I meant OCP 8 question bank. I will change the jdk version to 8. Thanks for the quick replay.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests