Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:20:11+00:00 2026-06-13T10:20:11+00:00

K.Sierra in her book SCJP Study Guide mentions We know that a literal integer

  • 0

K.Sierra in her book “SCJP Study Guide” mentions “We know that a literal integer is always an int, but more importantly, the result of an expression involving anything int-sized or smaller is always an int.”

I’ve started experimenting and I’m a little bit confused with the below results:

byte a = 1; // correct
byte b = 1 + a; // incorrect (needs explicit casting)
byte c = 1 + 1; // correct (I expected it to be incorrect)

Could anyone explain to me why the last example does not require casting? Why does the Java compiler put the implicit cast? Is it because there are 2 int literals? Clarification greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:20:12+00:00Added an answer on June 13, 2026 at 10:20 am

    Implicit typecasting only works when the value of your RHS is known at compile-time, means they are compile-time constants. In other cases, you need to do explicit typecasting.

    So: –

    byte c = 1 + 1; // Value of `1 + 1` is known at compile time. Implicit cast
    byte c = 1 + a; // Value of `1 + a` is evaluated at runtime. Explicit cast needed
    

    Also, note that, if you declare your variable a as final byte a = 1, then the 2nd assignment will compile, as in that case, your a will be a compile time constant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm studying for SCJP, and my book (Sierra's) says about the Formatter class that
In Kathy Sierra's book on SCJP we learn that, When we write List <A>
In the book of SCJP guide by Kathy Sierra, in the assignments chapter, we
The SCJP 6 Study Guide from Bert Bates and Kathy Sierra states on page
I am currently studying for the SCJP certification using the Sierra and Bates Study
I read in Kathy Sierra book that when we create String using new operator
Just reading Kathy Sierra/Bert Bates: JSCP Java6 Study Guide and found contradicting mock exam
I am reading the SCJP 6 book by Sierra and Bates. In the first
I am reading the SCJP book by Kathy Sierra. I find Polymorphism a little
I'm reading SCJP Java 6 by Kathy Sierra and Bert Bates and this book

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.