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 1080891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:05:49+00:00 2026-05-16T22:05:49+00:00

I understand that the following code won’t work Float a=3 because its translated as

  • 0

I understand that the following code won’t work

Float a=3

because its translated as Float a=Integer.valueOf(3). We’ll have a Float reference on the LHS and an Integer object on the RHS, which is incompatible. But :

1.

     `Short a=3;`

This works, though here again, we’ll have a Short reference on the LHS and an Integer object on the RHS.

2.

Float a=(Float) 3

If we hadn’t typecasted 3, it would have been translated as Integer.valueOf(3). Now, will it be translated as Float.valueOf(3) ?

  • 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-05-16T22:05:50+00:00Added an answer on May 16, 2026 at 10:05 pm

    If you try to initialize a variable with a value bigger than it can hold (regardless of the numerical form of the value), the compiler will give you an error message.

    char c = 0xffff; // max char hex value
    byte b = 0x7f; // max byte hex value
    short s = 0x7fff; // max short hex value
    

    Notice in the above code the maximum possible hexadecimal values for char, byte, and short. If you exceed these, the compiler will automatically make the value an int and tell you that you need a narrowing cast for the assignment. You’ll know you’ve stepped over the line.

    So in your case Short s = 3 actually becomes Short s = new Short(3) and works. (valueOf methods are not used when Autoboxing that is why modern IDEs have options to flag these autoboxing as errors and we can replace them with the valueOf method for better mgmt of memory)

    In the second case Float a=(Float) 3 will become Float.valueOf(3)

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

Sidebar

Related Questions

I understand that the following code won't work, as i is a runtime parameter
I have the following code that won't compile and although there is a way
I understand that using the === compares type, so running the following code results
So, I understand that the following doesn't work, but why doesn't it work? interface
I understand that some countries have laws regarding website accessibility. In general, what are
I understand that these methods are for pickling/unpickling and have no relation to the
Hy all, I believe that the following piece of code is generating memory leak?
Read that the following code is an example of unsafe construction as it allows
I have the following code... - (void)textFieldDidBeginEditing:(UITextField *)textField { //some code here... NSInteger theTag
I understand that there are several ways to blend XNA and WPF within the

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.