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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:58:10+00:00 2026-05-13T19:58:10+00:00

I was doing one of these online Java tests and I was asked this

  • 0

I was doing one of these online Java tests and I was asked this question:

Q: Indicate correct assignment:

Long l = 1; 
Double d = 1;
Integer i = 1;
String s = 1;
Object o = "1";
System.out.println(o);
o = 1;
System.out.println(o);

Please try it yourself before you go any further.

Well I can tell you I got it wrong, I investigated it and found:

//Long l = 1; //cannot widen and then box
Long ll = 1L;//no need to widen, just box
//Double d = 1;//cannot widen and then box
Double dd = 1d;//no need to widen, just box
Integer i = 1;//no need to widen, just box
//String s = 1;//cannot do implicit casting here

Object o = "1";//this compiles and is just plain weird 
System.out.println(o);//output is 1
o = 1;//this also compiles and is also weird 
System.out.println(o);//output is 1

Can someone tell why:

Object o = 1; and Object o = "1";

compile and output 1 in both cases, this is puzzling me.

Many thanks

  • 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-13T19:58:10+00:00Added an answer on May 13, 2026 at 7:58 pm

    "1" is an instance of String class, and String is a subclass of Object class in Java (as any other class). 1 is boxed into an Integer, which is also derived from Object.

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

Sidebar

Related Questions

I'm doing these free online Stanford classes and learning Java. I'm stuck on something
This one is a case of not doing your homework.:-) Apart from dynamic loading
Once again one of those: Is there an easier built-in way of doing things
There are many ways of doing debugging, using a debugger is one, but the
I am very new to grails.I am doing one sample project for image uploading
I'm about to start a project where I will be the only one doing
Some people have suggested that when doing an estimate one should make a lower
One thing I've started doing more often recently is retrieving some data at the
One of the things I'm doing includes several links on the show view. For
I have one console app that is doing some lengthy syncing to an ftp

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.