Results 1 to 2 of 2
  1. #1
    aga010607 is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Question Java arrays (not sure if this question is advanced)

    For design convenience I need to implement an attribute in a superclass as

    double[][] myArray2D = new double[M][N]

    which is used in most subclasses with M>>1 and N>>1. However, a couple of subclasses only require

    double[][] myArray2D = new double[1][N]

    or

    double[] myArray1D = new double[N].

    Is there a difference in memory allocation and in computational efficency between implementing myArray1D[N] and myArray2D[1][N]??

    Thank you. AGA

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Quote Originally Posted by aga010607 View Post
    For design convenience I need to implement an attribute in a superclass as

    double[][] myArray2D = new double[M][N]

    which is used in most subclasses with M>>1 and N>>1. However, a couple of subclasses only require

    double[][] myArray2D = new double[1][N]

    or

    double[] myArray1D = new double[N].

    Is there a difference in memory allocation and in computational efficency between implementing myArray1D[N] and myArray2D[1][N]??

    Thank you. AGA
    say you have a constructor

    Java Code:
    SuperClass(int M, int N ) {
        myArray2D = new double[M][N];
         ...
    then the other classes simply do
    Java Code:
    ChildClass(int N) {
       super(1, N);
    You only declare slots that you need.

Similar Threads

  1. Question about 2D arrays
    By fanle in forum New To Java
    Replies: 7
    Last Post: 07-22-2009, 05:52 PM
  2. Byte arrays and MIDI - simple question?
    By Ravaa in forum New To Java
    Replies: 1
    Last Post: 03-23-2009, 09:47 PM
  3. Arrays Problem (Advanced Java...Need Help)
    By Zebra in forum New To Java
    Replies: 9
    Last Post: 05-02-2008, 01:26 AM
  4. question about arrays
    By broganm1 in forum New To Java
    Replies: 3
    Last Post: 02-13-2008, 02:29 AM
  5. Question about arrays
    By nhlfan in forum New To Java
    Replies: 4
    Last Post: 11-15-2007, 11:38 AM

Posting Permissions

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