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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:47:00+00:00 2026-06-09T00:47:00+00:00

Suppose I have class MyObject { Object object1 = new Object(); Object object2; public

  • 0

Suppose I have

class MyObject
{
    Object object1 = new Object();
    Object object2;

    public MyObject()
    {
        object2 = new Object();
    }

    public MyObject(Object object2)
    {
        this.object2 = object2;
    }

    public MyObject(Object object1, Object object2)
    {
        this.object1 = object1;
        this.object2 = object2;
    }
}

When does object1 get initialized? Before object2, after object2, depends?

What happens if I have a constructor that conflicts with the global definition of object1, e.g. in the third constructor above. Which value does object take?

This isn’t causing me any problems but I just wanted to understand the language a bit better. I like to know these little things so that I could potentially make use of them later on.

  • 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-09T00:47:01+00:00Added an answer on June 9, 2026 at 12:47 am
    • The variables are initialized to the default values for their type (0, null etc)

    • First the superclass constructor is called. If the superclass constructor calls any virtual methods overridden in this class, the override will see the default values, regardless of any variable initializers or initialization in the constructor body.

    • Then variable initializers are executed.

    • Then the constructor body is executed.

    So if you change the value of a variable within the constructor body, any value set by the variable initializer will be overwritten. (The previous value could have been used in other chained constructors etc, of course.)

    See section 12.5 of the JLS for more details.

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

Sidebar

Related Questions

Suppose I have the following: public class MyObject { public string Name {get; set;}
Let's suppose I have this object: [Serializable] public class MyClass { public int Age
Suppose you have a list of MyObject like this: public class MyObject { public
Suppose I have: class Foo { public String Bar { get; set; } }
Suppose I have this class: class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = foo self.attr2
I have a class like this public SomeClass { private List<string> _strings = new
I have a class that represents some business object, such as this: Public Class
Suppose I have class A { public List<B> LiProperty { get; set { //will
Suppose I have: class Foo { public int Bar { get; set; } }
Suppose I have a class with overloaded operator new . class Class { public:

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.