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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:14:38+00:00 2026-05-10T23:14:38+00:00

What happens in the memory when a class instantiates the following object? public class

  • 0

What happens in the memory when a class instantiates the following object?

public class SomeObject{      private String strSomeProperty;      public SomeObject(String strSomeProperty){         this.strSomeProperty = strSomeProperty;     }     public void setSomeProperty(String strSomeProperty){         this.strSomeProperty = strSomeProperty;     }     public String getSomeProperty(){         return this.strSomeProperty;     } } 

In class SomeClass1:

SomeObject so1 = new SomeObject('some property value'); 

In class SomeClass2:

SomeObject so2 = new SomeObject('another property value'); 

How is memory allocated to the newly instantiated object and its properties?

  • 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. 2026-05-10T23:14:39+00:00Added an answer on May 10, 2026 at 11:14 pm

    Let’s step through it:

    SomeObject so1 = new SomeObject('some property value'); 

    … is actually more complicated than it looks, because you’re creating a new String. It might be easier to think of as:

    String tmp = new String('some property value'); SomeObject so1 = new SomeObject(tmp); // Not that you would normally write it in this way. 

    (To be absolutely accurate – these are not really equivalent. In the original the ‘new String’ is created at compile time and is part of the .class image. You can think of this as a performance hack.)

    So, first the JVM allocates space for the String. You typically don’t know or care about the internals of the String implementation, so just take it on trust that a chunk of memory is being used to represent ‘some property value’. Also, you have some memory temporarily allocated containing a reference to the String. In the second form, it’s explicitly called tmp; in your original form Java handles it without naming it.

    Next the JVM allocates space for a new SomeObject. That’s a bit of space for Java’s internal bookkeeping, and space for each of the object’s fields. In this case, there’s just one field, strSomeProperty.

    Bear in mind that strSomeProperty is just a reference to a String. For now, it’ll be initialised to null.

    Next, the constructor is executed.

    this.strSomeProperty = strSomeProperty; 

    All this does is copy the reference to the String, into your strSomeProperty field.

    Finally, space is allocated for the object reference so1. This is set with a reference to the SomeObject.

    so2 works in exactly the same way.

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Why not just cat each repo's git log to its… May 11, 2026 at 10:09 am
  • added an answer There was a recent disussion about this exact topic on… May 11, 2026 at 10:09 am
  • added an answer MSDN says about the NONCLUSTERED argument: This is the only… May 11, 2026 at 10:09 am

Related Questions

What happens in the memory when a class instantiates the following object? public class
Question in the title. And what happens when all 3 of $_GET[foo] , $_POST[foo]
I'll go first. I'm 100% in the set-operations camp. But what happens when the
What happens when the Office 2003 PIA prerequisite and launch condition in a Windows
Is there a foreach structure in MATLAB? If so, what happens if the underlying
What happens to exceptions raised while in myMethod: if it is invoked via NSObject's
What happens if I use SHGetFolderPath api call in a 32 bit system with
What happens to the name/value pairs stored inside a form's resx file? Are they
What happens on a Windows box once you add more drives than can fit
what happens if an user trying to read HttpContext.Current.Cache[key] while the other one trying

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.