Page 1 of 1
About Question enthuware.ocpjp.v11.2.3488 :
Posted: Thu Feb 11, 2021 5:06 pm
by OliviaJohnson
Hello, option B
i1 == i3 does not compile. The error is
Code: Select all
Syntax error on token "==", invalid AssignmentOperator
I just copy and pasted your code into IDE
Code: Select all
public class main {
public static void main(String[] args) throws Exception {
Integer i1 = 1;
Integer i2 = new Integer(1);
int i3 = 1;
Byte b1 = 1;
Long g1 = 1L;
Double d = 1.0;
i1 == i3;
i1.equals(i2);
}
}
Re: About Question enthuware.ocpjp.v11.2.3488 :
Posted: Thu Feb 11, 2021 10:17 pm
by admin
i1 == i3; is indeed an invalid statement. But it is a valid expression that returns true, which is why this option is correct. (All of the given options are just expressions.)
You may try this:
boolean b = (i1 == i3);
System.out.println(b);
Re: About Question enthuware.ocpjp.v11.2.3488 :
Posted: Thu Aug 01, 2024 11:22 am
by Badem48
Hi,
You know
is depreciated.
factory method is being use.
Additionally,
Code: Select all
Integer i1 = 1;
Integer i2 = Integer.valueOf(1);
System.out.println(i1 == i2);
Returns true.
Re: About Question enthuware.ocpjp.v11.2.3488 :
Posted: Tue Oct 08, 2024 1:41 am
by ShabnamLK
Hi,
for Integer i2 = new Integer(1);
I can see that the answer explains in the end - Note that constructors of wrapper objects such as Integer have been deprecated (marked for removal since Java 9), but moreover it also gives compilation error in IDE.
So boolean expressions involving i2 may want to be disregarded in the correct options I would think?
Re: About Question enthuware.ocpjp.v11.2.3488 :
Posted: Tue Oct 08, 2024 2:07 am
by admin
>but moreover it also gives compilation error in IDE.
Don't use IDE for testing code while preparing for certification exam because they give different errors than command line tools.
https://enthuware.com/oca-ocp-java-cert ... cation-ide
Re: About Question enthuware.ocpjp.v11.2.3488 :
Posted: Tue Oct 08, 2024 5:52 pm
by ShabnamLK
Many thanks, you are right. From command line tool this usage is only shown as a compiler warning. Much appreciated.