abstract class need acces to subclass atribute

Posted by user1742980 on Stack Overflow See other posts from Stack Overflow or by user1742980
Published on 2012-11-05T22:44:41Z Indexed on 2012/11/05 23:00 UTC
Read the original article Hit count: 204

Filed under:
|

I have a problem with my code.

public abstract class SimplePolygon implements Polygon
{
               ...

public String toString(){
    String str = "Polygon: vertices ="; 
    for(int i = 0;i<varray.length;i++){
        str += " ";
        str += varray[i];
    }
    return str;
}
}

public class ArrayPolygon extends SimplePolygon
{
private Vertex2D[] varray;
public ArrayPolygon(Vertex2D[] array){
    varray = new Vertex2D[array.length];
    if (array == null){}
    for(int i = 0;i<array.length;i++){
        if (array[i] == null){}
        varray[i] = array[i];
    }
                ...
}

Problem is, that i'm not allowed to add any atribute or method to abstract class SimplePolygon, so i'cant properly initialize varray. It could simply be solved with protected atrib in that class, but for some (stupid) reason i'cant do that. Has anybody an idea how to solve it without that? Thanks for all help.

© Stack Overflow or respective owner

Related posts about java

Related posts about abstract-class