// Abstract class Instrument
// Abstract method to be implemented by subclasses
abstract void play();
// Abstract method to be implemented by subclasses
abstract void tune();
}
// Subclass Glockenspiel that extends Instrument
@Override
void play() {
System.
out.
println("Playing the Glockenspiel."); }
@Override
void tune() {
System.
out.
println("Tuning the Glockenspiel."); }
}
// Subclass Violin that extends Instrument
@Override
void play() {
System.
out.
println("Playing the Violin."); }
@Override
void tune() {
System.
out.
println("Tuning the Violin."); }
}
// Main class to test the program
public class Main {
public static void main
(String[] args
) { // Create instances of Glockenspiel and Violin
// Call methods on the instances
glockenspiel.play();
glockenspiel.tune();
violin.play();
violin.tune();
}
}
Ly8gQWJzdHJhY3QgY2xhc3MgSW5zdHJ1bWVudAphYnN0cmFjdCBjbGFzcyBJbnN0cnVtZW50IHsKICAgIC8vIEFic3RyYWN0IG1ldGhvZCB0byBiZSBpbXBsZW1lbnRlZCBieSBzdWJjbGFzc2VzCiAgICBhYnN0cmFjdCB2b2lkIHBsYXkoKTsKICAgIAogICAgLy8gQWJzdHJhY3QgbWV0aG9kIHRvIGJlIGltcGxlbWVudGVkIGJ5IHN1YmNsYXNzZXMKICAgIGFic3RyYWN0IHZvaWQgdHVuZSgpOwp9CgovLyBTdWJjbGFzcyBHbG9ja2Vuc3BpZWwgdGhhdCBleHRlbmRzIEluc3RydW1lbnQKY2xhc3MgR2xvY2tlbnNwaWVsIGV4dGVuZHMgSW5zdHJ1bWVudCB7CiAgICBAT3ZlcnJpZGUKICAgIHZvaWQgcGxheSgpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlBsYXlpbmcgdGhlIEdsb2NrZW5zcGllbC4iKTsKICAgIH0KICAgIAogICAgQE92ZXJyaWRlCiAgICB2b2lkIHR1bmUoKSB7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJUdW5pbmcgdGhlIEdsb2NrZW5zcGllbC4iKTsKICAgIH0KfQoKLy8gU3ViY2xhc3MgVmlvbGluIHRoYXQgZXh0ZW5kcyBJbnN0cnVtZW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