Results 1 to 3 of 3
  1. #1
    sln69 is offline Member
    Join Date
    Oct 2008
    Rep Power

    Default Array initialization difference

    Hi, can anybody tell me the difference betweeen

    ClassX inst[] = { new ClassX() };


    ClassX[] inst = null;
    inst[0] = new ClassX();

    What modifications should be made in the second paragraph to make it work?


  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Rep Power

    Default hhhmmm... maybe...

    In the second example it looks like you're trying to instantiate a class into an array (not assign a class as the first element of an array). Maybe this would work:
    Java Code:
      ClassX[] inst = null;
      ClassX myClassX = new ClassX();
      inst[0] = { myClassX };

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    Have you written a test program to see what the difference is?
    Would save a lot of time and the answer would be correct.

    The second line group creates a pointer but does NOT create an instance of an array. Ie inst[0] does not exist.
    Does the first one compile?

Similar Threads

  1. variable initialization
    By rqal.10 in forum New To Java
    Replies: 5
    Last Post: 06-15-2008, 07:39 AM
  2. 2D Array Initialization
    By M77 in forum Advanced Java
    Replies: 3
    Last Post: 06-04-2008, 03:12 PM
  3. initialization value problem
    By ravian in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 11:54 AM
  4. Lazy Initialization
    By onegcr in forum New To Java
    Replies: 1
    Last Post: 08-14-2007, 04:29 PM
  5. log4j initialization
    By arfatkhan in forum Web Frameworks
    Replies: 3
    Last Post: 08-10-2007, 08:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts