I have a class called WallTile
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class WallTile extends Tile
{
private int x;
private int y;
private int id=1;
private ImageIcon image;
private String[] flags=new String[]{"[IMPASSABLE]", "[SIGHT_BLOCKER]"};
public WallTile(int x, int y)
{
this.x=x;
this.y=y;
if((int)(Math.random()*2)==0){
this.image=Sprites.WALLTILE1_SP;
}
else{
this.image=Sprites.WALLTILE2_SP;
}
}
}
which inherits from class Tile
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Tile
{
private int x;
private int y;
private int id;
private ImageIcon image;
private String[] flags;
public int getX(){
return(this.x);
}
public int getY(){
return(this.y);
}
public int getId(){
return(this.id);
}
public ImageIcon getImage(){
//System.out.println(this.image);
return(this.image);
}
public String[] getFlags(){
return(this.flags);
}
public boolean testFlag(String test){//returns true if flag is not present
return(java.util.Arrays.asList(this.flags).indexOf(test)==-1);
}
}
creating an instance of wallTile and calling a method defined in Tile always returns null e.x:
WallTile wall = new WallTile(3,7);
System.out.println(wall.getImage());//returns null
However, if I copy one of the functions from Tile and paste it into WallTile, that function returns the correct value.
Is there any to call the functions defined in tile with an instance of WallTile without having to copy all of the functions defined in tile over to WallTile?