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]);
See comments in code below. Apply same thinking to class C.
Adam
publicclass 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;
}
}