• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Rules Roundup Q45  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume the questions are the same, but to clarify, I am using the beta of the second version.
The question asks:
45) Integer literals are always what size?
The answer given is:
Integer literals are always treated as 32-bit ints.
However, this is disproven by the following code: attempting to assign an integer literal to a byte works just fine, while attempting to assign the same integer causes a problem. I think the correct response is, "Integer literals are always treated as the smallest integer-type that can hold them without an overflow."
------------->
byte b = 5; //This works just fine!
int xx = 5;
b = xx; //This causes an error!
 
Jeff L.
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this thread after I posted.
http://www.coderanch.com/t/190639/java-programmer-SCJP/certification/integer-literals
Note that I searched for Integer literal before posting, but I restricted my search to the mock exam, and missed the discussion elsewhere.
This proves that my surmise about byte is wrong, but int is a little misleading. Actually, it treats Integer literals as final ints rather than unadorned ints. (Ok, I'm splitting hairs so at least I'm not completely wrong... )
Anyway, I thought I'd share the results.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff,
Your display name does not comply with our naming policy so I'll have to ask you to change it.
Thanks.
 
Do not set lab on fire. Or this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!