About Question enthuware.ocpjp.v17.2.3721 :

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

Moderator: admin

Post Reply
Val Martinez
Posts: 11
Joined: Thu Sep 01, 2022 10:58 am
Contact:

About Question enthuware.ocpjp.v17.2.3721 :

Post 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

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

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

Post by admin »

No, it doesn't. Please make sure you have copied the code correctly.
If you like our products and services, please help us by posting your review here.

Badem48
Posts: 26
Joined: Thu Aug 24, 2023 4:33 pm
Contact:

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

Post 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"); }
}

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

likejudo
Posts: 24
Joined: Sun Feb 18, 2024 7:21 pm
Contact:

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

Post 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?

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

likejudo
Posts: 24
Joined: Sun Feb 18, 2024 7:21 pm
Contact:

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

Post 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.

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests