I have this problem with my code and I don't know how to resolve it please help me.
No enclosing instance of type Hra
is accessible. Must qualify the allocation with an enclosing instance of type Hra
(e.g. x.new A()
where x
is an instance of Hra
)."
public class Hra {
public static void main(String[] args) {
Hrac h = new Cerveny(1); // there is that error
int result = h.zautoc(55, 30);
System.out.print(0);
}
public Hrac[] pole;
private int counter;
public Hra() {
this.pole = new Hrac[100];
this.counter = 0;
}
public void pridajHraca(Hrac h) {
this.pole[counter] = h;
}
public abstract class Hrac{
protected double zivot;
public int tim;
public int zautoc(int velkost, int mojaPozicia){
if (tim == 1){
if (mojaPozicia >= 7)
return (mojaPozicia -7);
else
return (velkost - 7 - mojaPozicia);
}
if (tim == 2){
if (mojaPozicia +3 <= velkost)
return (mojaPozicia +3);
else
return (mojaPozicia -velkost +3 );
}
return 0;
}
}
public class Cerveny extends Hrac{
public Cerveny(double _zivot) {
super.zivot = _zivot;
super.tim = 1;
}
}
public class Cierny extends Hrac{
public Cierny(double _zivot) {
super.zivot = _zivot;
super.tim = 2;
}
}
}