Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
Moderator: admin
Val Martinez
Posts: 11 Joined: Thu Sep 01, 2022 10:58 am
Contact:
Post
by Val Martinez » Wed Jun 07, 2023 5:15 am
As for me, the first option marked as wrong,
does work perfectly in a real enviroment with JDK17
admin
Site Admin
Posts: 10036 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Wed Jun 07, 2023 11:22 am
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:
Post
by Badem48 » Tue Jan 30, 2024 9:54 am
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: 10036 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » 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.
If you like our products and services, please help us by posting your
review here .
Users browsing this forum: Google [Bot] and 40 guests