My goal is to print out that all the instruments are playing by creating the testInstrument.java file. For some reason I am getting an error for System.out.println(all[i].play());
testInstrument.java
package my_instruments;
public class testInstrument {
public static void main(String[] args) {
// TODO Auto-generated method stub
Guitar g = new Guitar();
Flute f = new Flute();
Piano p = new Piano();
Instrument[] all = new Instrument[3];
all[0] = g;
all[1] = f;
all[2] = p;
for (int i=0; i<3; i++) {
System.out.println(all[i].play());
}
}
}
Instrument.java
package my_instruments;
public class Instrument {
public Instrument() {
}
public void play() {
System.out.println("Playing instrument");
}
}
Piano.java
package my_instruments;
public class Piano extends Instrument{
public Piano() {
super();
}
public void play() {
System.out.println("Playing piano");
}
}
play()method exist inInstrumentclass? Does it return anything? Please post the contents of those classes too.InstrumentandGuitar,PianoandFlute? It may seem obvious and apparent to you but without actual source code to go off of, we're left in the dark here.