Java filling arrays and inheritance

I think I'm facing a conceptual inheritance wall with my Java arrays. I'm a little new to Java, so please tell me if I have something upside down. In essence, I want to do three things:

  • Create a runnersArray with the attributes of my Runners class.
  • Populate my runnersArray using my GenerateObjects method of my GenerateObjects class.
  • Access the contents of my filled runnersArray in my evaluation method of my evaluation class.

The problem is that runnersArray is not displayed for the methods described in steps 2 and 3 above, but their classes (due to design reasons) cannot inherit or extend the Runners class.

Thanks in advance for any suggestions.

Here are some code snippets showing what I'm trying to do:

public class Runners extends Party {

    Runners[] runnersArray = new Runners[5];
}

and

public class GenerateObject extends /* certain parent class */ {

     public GenerateObject (int arrayNum) {
          runnersArray[arrayNum] = /* certain Runners attributes */;
     }
}

and

public class Evaluating extends /*certain parent class*/ {

     public Evaluating (int arrayNum) {
          System.out.println(/* String cast attribute of runnersArray[arrayNum]*/;
     }
}
+3
1

, , runnersArray - package-private ( , -private) Runners. , GenerateObject Evaluating.

, runnersArray , , .

public class Runners extends Party {
    public static Runners[] runnersArray = new Runners[5];
}

, :

public class GenerateObject extends /* certain parent class */ {
    public GenerateObject (int arrayNum) {
        Runners.runnersArray[arrayNum] = /* certain Runners attributes */;
    }
}

, .

+2

Source: https://habr.com/ru/post/1739936/


All Articles