Page 1 of 1

About Question enthuware.ocajp.i.v8.2.1247 :

Posted: Sat May 19, 2018 5:01 am
by flex567
What is implicit narowing?

I would assume that it is:
assign a larger type value to a variable of smaller type without programmer doing it?

Re: About Question enthuware.ocajp.i.v8.2.1247 :

Posted: Sun May 20, 2018 12:40 pm
by admin
This discussion should be helpful: https://stackoverflow.com/questions/278 ... es-in-java

But yes, "narrowing" is when a larger type (such as int) (or in case reference types, a super type) is assigned to a variable of of a smaller type (such as byte) (or in case of reference types, a sub type) and "implicit" means without using an explicit cast. Narrowing can therefore happen for primitives as well as for reference types. But implicit narrowing happens only in the case of primitives and only during assignment of constant expressions.

Re: About Question enthuware.ocajp.i.v8.2.1247 :

Posted: Fri May 25, 2018 5:18 pm
by flex567
Is there a way to create a short literal?

Re: About Question enthuware.ocajp.i.v8.2.1247 :

Posted: Mon May 28, 2018 9:24 pm
by admin
No, and not a byte literal either.

Re: About Question enthuware.ocajp.i.v8.2.1247 :

Posted: Sat Jan 05, 2019 2:50 pm
by crazymind
Hi, Does OCA require to remember the widening or narrowing conversion? Is there an easy way to remember it? Thanks

Re: About Question enthuware.ocajp.i.v8.2.1247 :

Posted: Sat Jan 05, 2019 7:34 pm
by admin
Yes, you need to know this for the exam. There are only a few simple rules that govern it. You will have to memorize these rules. I am not aware of any other way.