About Question com.enthuware.ets.scjp.v6.2.56 :

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

Moderator: admin

Post Reply
piotrkmiotczyk
Posts: 27
Joined: Mon Sep 22, 2014 1:30 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.56 :

Post by piotrkmiotczyk »

I'm being linked here from a completely different questions. Mine is a DnD about which operators are legal between which types.
Are the codes not unique?

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

Re: About Question com.enthuware.ets.scjp.v6.2.56 :

Post by admin »

Should be fixed now.
If you like our products and services, please help us by posting your review here.

piotrkmiotczyk
Posts: 27
Joined: Mon Sep 22, 2014 1:30 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.56 :

Post by piotrkmiotczyk »

Why does this work:

char c = 'a';
Integer i = 9;
c += i;

I thought adding char to integer causes promotion of char to int (Integer is unboxed to int) and then the result is int type, but IS NOT a constant expression.

The below (with the same declarations) does not work for precisely this reason (and both are char + int assigned to char):

c = 'a'+i;

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

Re: About Question com.enthuware.ets.scjp.v6.2.56 :

Post by admin »

Because java compiler converts c += i; to c = (char)(c+i); It adds an explicit cast.
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 52 guests