interface Instrument{
public void play();
}
We have implemented several instruments (piano, guitar,...):
class Piano implements Instrument {
public void play(){
System.out.println("playing the piano...");
}
}
class Guitar implements Instrument
{
public void play(){
System.out.println("playing the guitar...");
}
}
class Flute implements Instrument {
public void play(){
System.out.println("playing the flute...");
}
}
class Conductor {
public static void
main(String[] args) {
try{
for(int i = 0; i < args.length; i++){
Instrument instrument = (Instrument)Class.forName(args[i]).newInstance();
instrument.play();
}
}
catch(Exception e){
System.out.println("Problem in conductor " + e);
}
}
}