Page 1 of 1

About Question enthuware.ocpjp.v17.2.3721 :

Posted: Wed Jun 07, 2023 5:15 am
by Val Martinez
As for me, the first option marked as wrong,

Code: Select all

if (a instanceof A a1) a1.a();
does work perfectly in a real enviroment with JDK17

Re: About Question enthuware.ocpjp.v17.2.3721 :

Posted: Wed Jun 07, 2023 11:22 am
by admin
No, it doesn't. Please make sure you have copied the code correctly.

Re: About Question enthuware.ocpjp.v17.2.3721 :

Posted: Tue Jan 30, 2024 9:54 am
by Badem48
I do not know if it is just me but this code, which is first option works on my machine?

Code: Select all

public class TestClass {
    public static void main(String[] args) {
        B b = new C();
        A a = b;
        if (a instanceof A a1) a1.a();

    }
}

class A {
    void a(){ System.out.println("a"); }
}
class B extends A {
    void b(){ System.out.println("b"); }
}
class C extends B {
    void c(){ System.out.println("c"); }
}

Re: About Question enthuware.ocpjp.v17.2.3721 :

Posted: Tue Jan 30, 2024 9:56 am
by admin
It doesn't compile on Java 17 but compiles on Java 21.
This is due to a change in the Java language specification for instanceof.

Re: About Question enthuware.ocpjp.v17.2.3721 :

Posted: Sat Apr 20, 2024 9:06 pm
by likejudo
admin wrote:
Tue Jan 30, 2024 9:56 am
It doesn't compile on Java 17 but compiles on Java 21.
This is due to a change in the Java language specification for instanceof.
Then why is the question on the exam?

Re: About Question enthuware.ocpjp.v17.2.3721 :

Posted: Sun Apr 21, 2024 12:31 am
by admin
Not sure what is your question. Do you mean why this question is there in our mock exams? It is because this topic is on the OCP 17 exam. The answer and the explanation provided in the s/w are as per Java 17.

Re: About Question enthuware.ocpjp.v17.2.3721 :

Posted: Sun Apr 21, 2024 8:22 am
by likejudo
admin wrote:
Sun Apr 21, 2024 12:31 am
Not sure what is your question. Do you mean why this question is there in our mock exams? It is because this topic is on the real OCP 17 exam. The answer and the explanation are as per Java 17.
Thanks. You mentioned that it does not compile on 17, but on 21. If I understood your comment above.

Re: About Question enthuware.ocpjp.v17.2.3721 :

Posted: Sun Apr 21, 2024 10:05 am
by admin
That was in response to another user. It worked on their system most likely because they were using Java 21. It works on Java 21 because of the reason mentioned above. But the exam is for Java 17, so option 1 is incorrect.