Java, filling arrays, and inheritance
        Posted  
        
            by Arvanem
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Arvanem
        
        
        
        Published on 2010-04-06T02:45:19Z
        Indexed on 
            2010/04/06
            2:53 UTC
        
        
        Read the original article
        Hit count: 443
        
Hi folks, I think I'm running into an inheritance conceptual wall with my Java arrays. I'm kind of new to Java so please tell me if I have things upside down. In essence, I want to do three things:
- Create a runnersArray with the attributes of my Runners class.
- Fill my runnersArray using my GenerateObjects method of my GenerateObjects class.
- Access the contents of my filled runnersArray in my Evaluating method of my Evaluating class.
The problem seems to be that runnersArray is not visible to the methods in steps 2 and 3 above, but their classes (due to design reasons) cannot inherit or extend 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]*/;
     }
}
© Stack Overflow or respective owner