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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:34:42+00:00 2026-06-04T23:34:42+00:00

As far as the initial/default/uninitialized value of is concerned… …Are array objects initialized (at

  • 0

As far as the initial/default/uninitialized value of is concerned…
…Are array objects initialized (at class and local levels)?

Read it in some SCJP notes:

Array elements are given their default values regardless of whether
the array is declared as an instance or local variable.

Array “objects” however will not be initialized if it is declared
locally.

  • 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-04T23:34:43+00:00Added an answer on June 4, 2026 at 11:34 pm

    Class members that are reference types get an initial value of null.

    Local variables that are reference types are considered unitialized and need to be assigned null or something else explicitly, else the code will not compile.

    Try to test this example and see what happens:

    class Test {
        private Object[] member;
    
        public void foo() {
            member.toString(); // NullPointerException
            Object[] local;
            local.toString(); // won't compile: The local variable local may not have been initialized
        }
    }
    

    Arrays of objects obey the same rules, since they are references themselves.

    Now, that’s for the array itself. When speaking about the actual elements of the array, they are null by default regardless of where you declare them:

    class Test {
        private Object[] member = new Object[10];
    
        public void foo() {
            member[0].toString(); // NullPointerException
            Object[] local = new Object[10];
            local[0].toString(); // NullPointerException
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Far as best practices are concerned, which is better: public void SomeMethod(string str) {
As far as I know, only the convenience methods return created objects with an
As far as I'm concerned, Ajax provides a workaround for behaving like connection-oriented with
I'm having some difficulty with a CSS only menu in Ie7. So far the
I wanted to write some code like this: class SomeModel(models.Model): field = models.ForeignKey(SomeOtherModel) def
The answer to this question: What is the initial value of a JavaScript function's
I am trying to have a textfield with an initial value, where if you
As far as i know, there is no direct equivalent in C#. My current
so far i only know to use Ctrl-Shift-A to do SVN in TextMate. is
As far as I know there is no way to do this, but I

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.