保護された属性の高さを持つ子 (拡張) クラスがあります。メインプログラムでアクセスしたい:
while(line != null)
{
String[] field = line.split("#");
int height = Integer.parseInt(field[0]);
if (field.length ==1)
{
forest[cnt] = new Trees(height);
}
else
{
forest[cnt] = new Shrub(height, field[1]);
}
cnt++;
line = inS.readLine();
}
inS.close();
String s = JOptionPane.showInputDialog("Enter Name to search for");
for(int i = 0; i<forest.length; i++)
{
if (forest[i] instanceof Shrub)
{
String a = forest[i].getName();
System.out.println ("Found");
}
}
}
しかし、メソッドgetNameが見つからないというエラーが表示されますが、lol Shrubを実行すると正常に動作しますか?
ありがとう。