The Artima Developer Community
Sponsored Link

Java Answers Forum
Please Help - Array of objects ( classes)

1 reply on 1 page. Most recent reply: Jan 7, 2004 5:29 AM by Adam Duffy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Manny

Posts: 1
Nickname: manny
Registered: Jan, 2004

Please Help - Array of objects ( classes) Posted: Jan 6, 2004 5:51 AM
Reply to this message Reply
Advertisement
I have a Java problem. I hope someone can help me.

I want to use classes in java like structures in C. In general I want to use a
structure like bb[1].aa[2].x[1] where x is an int array aa is an array of classes (or objects) and bb is the same. So a is neste in b and b is nested in c

I have a class :

package j911;

public class A {

int x[] ={1,2};
int gg[] = new int[2];
public static void main( String args[] ){

}
public A() {

}
}

public class B {
A aa[] = new A[2];
aa[1].x[1]=4; // why can't I do this???????????????????????
public static void main( String args[] ){

}
public B() {
}

}

package j911;


public class C {

B bb[] = new B[4];
bb[1].aa.[1].x[1]==88; // and why can't I do this !!!!!!!!!!!!!!!!!??????????????????????

public static void main( String args[] ){
//System.out.println("hc bb[1].aa[2].x[1]=",bb[1].aa[2].x[1]);

}
public void CC() {

}
}


Thank you very much...

Manny Tuzman


Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: Please Help - Array of objects ( classes) Posted: Jan 7, 2004 5:29 AM
Reply to this message Reply
See comments in code below. Apply same thinking to class C.

Adam

public class B {
  // place code in constructor
  public B() {
    A aa[] = new A[2];
    // initialise each element of array
    for( int i = 0; i < aa.length; i++ ) {
        aa[i] = new A();
    }
    // now you can do this...
    aa[1].x[1]=4;
   }
}

Flat View: This topic has 1 reply on 1 page
Topic: JAXB - unmarshalling / marshalling xml comments Previous Topic   Next Topic Topic: This code won't work, I can't find my error, can anyone help???

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use