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?
About Question enthuware.ocajp.i.v8.2.1247 :
Moderator: admin
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1247 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1247 :
Is there a way to create a short literal?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1247 :
No, and not a byte literal either.
If you like our products and services, please help us by posting your review here.
-
- Posts: 85
- Joined: Mon Dec 24, 2018 6:24 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1247 :
Hi, Does OCA require to remember the widening or narrowing conversion? Is there an easy way to remember it? Thanks
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1247 :
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: rwilliams93 and 89 guests