Results 1 to 2 of 2
  1. #1
    samanesh is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default passing an array as argument

    i have a subclass that needs to call the constructor of it's superclass, so I use the "super()" method.
    however, the superclass has an array as one of it's parameters. so i first tried this:
    Java Code:
    int[] array = {1,2,3,4};
    super(array);
    but this does not work, since super() needs to be the first instruction of the constructor.
    does anyone know how to use an array as argument without initializing it in another line?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,701
    Rep Power
    8

    Default Re: passing an array as argument

    super(new int[]{1, 2, 3, 4});
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 1
    Last Post: 02-28-2012, 10:34 AM
  2. Passing method as argument
    By susieferrari in forum New To Java
    Replies: 26
    Last Post: 06-13-2011, 10:43 AM
  3. N dimensional array as argument?
    By foota in forum Advanced Java
    Replies: 16
    Last Post: 05-07-2011, 09:55 AM
  4. passing a .txt into an array
    By j_rod722 in forum New To Java
    Replies: 6
    Last Post: 02-07-2011, 11:45 PM
  5. Passing a 2D array
    By toymachiner62 in forum New To Java
    Replies: 6
    Last Post: 10-23-2009, 04:05 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
  •