About Question enthuware.ocpjp.v11.2.3488 :

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

Moderator: admin

Post Reply
OliviaJohnson
Posts: 7
Joined: Sat Jan 30, 2021 2:04 pm
Contact:

About Question enthuware.ocpjp.v11.2.3488 :

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

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

Re: About Question enthuware.ocpjp.v11.2.3488 :

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

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

Re: About Question enthuware.ocpjp.v11.2.3488 :

Post by Badem48 »

Hi,

You know

Code: Select all

new Integer(int num)
is depreciated.

Code: Select all

Integer.valueOf(int num)
factory method is being use.
Additionally,

Code: Select all

        Integer i1 = 1;
        Integer i2 = Integer.valueOf(1);
        System.out.println(i1 == i2);
Returns true.

ShabnamLK
Posts: 2
Joined: Thu Sep 19, 2024 10:00 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3488 :

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

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

Re: About Question enthuware.ocpjp.v11.2.3488 :

Post 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

ShabnamLK
Posts: 2
Joined: Thu Sep 19, 2024 10:00 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3488 :

Post by ShabnamLK »

Many thanks, you are right. From command line tool this usage is only shown as a compiler warning. Much appreciated.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests