Advertisement
Kotuara

Практика4.2

Dec 21st, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5.     public interface Instrument {
  6.         public void play();
  7.         public String KEY="До мажор";
  8.     }
  9.  
  10.     public static class Guitar implements Instrument {
  11.         int StringsQuantity = 6;
  12.         public void play() {
  13.             System.out.println("Играет гитара, у неё " +StringsQuantity+ " струн");
  14.         }
  15.     }
  16.  
  17.     public static class Drum implements Instrument {
  18.         String Size = "большого";
  19.         public void play() {
  20.             System.out.println("Играет барабан, он " +Size+ " размера");
  21.         }
  22.     }
  23.  
  24.     public static class Pipe implements Instrument {
  25.         int Diameter = 40;
  26.         public void play() {
  27.             System.out.println("Играет труба диаметром " +Diameter);
  28.         }
  29.     }
  30.  
  31.     public static void main(String[] args) {
  32.         Guitar Acoustic = new Guitar();
  33.         Drum Tambourine = new Drum();
  34.         Pipe Tube = new Pipe();
  35.         Instrument[] Band = new Instrument[] {Acoustic, Tambourine, Tube};
  36.         for (int i=0; i<3; i++) {
  37.             Band[i].play();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement