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

  • Home
  • SEARCH
  • 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 7569937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:17:29+00:00 2026-05-30T15:17:29+00:00

I recently went for a Java Interview where the interviewer asked me a question

  • 0

I recently went for a Java Interview where the interviewer asked me a question I could not answer. He asked me how I’d create a class whose instances can be assigned to a String, just like a string. Allow me to explain:

Say I create a class, MyClass and I create an object of it, say obj. The assignment should be such that:

MyClass obj = "my Text";

I searched for this sort of thing but could not get any precise answers.

  • 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-30T15:17:30+00:00Added an answer on May 30, 2026 at 3:17 pm

    You say “assigned to a String” but your code example shows being assigned a String value. These are very different things. The former is easy: just write a toString() method in MyClass. The latter is basically impossible since String is a final class.

    More technically with respect to the last point: If you look at the rules for assignment conversion, a String value can only be assigned to a variable of type String or some wider reference type. The only wider reference types are Object, CharSequence, Serializable, and Comparable<String>. (Tip of the hat to Stephen C).

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

Sidebar

Related Questions

This question was recently asked to me in an interview for which i went
I had an interview recently where I was asked to produce the traditional FizzBuzz
I recently started learning Emacs . I went through the tutorial, read some introductory
As recently as several years ago, the developers actually made the builds that went
i've recently released an app to the App store, i went to have a
I recently jumped back into programming and decided to learn Java as my first
I recently went to backup a database and got the following error #1007 -
I recently went to the WROX forum. I was led there by GOOGLE. On
We recently went into private beta on our flagship product and had a small
I recently went through my CSS file and switched all my six-digit hexadecimal codes

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.