Advertisement
Kotuara

Практика4.1

Dec 21st, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5.     public interface Printable {
  6.         public void print();
  7.     }
  8.  
  9.     public static class Book implements Printable {
  10.         public void print() {
  11.             System.out.println("Книга");
  12.         }
  13.         public static void printBooks(Printable[] printable) {
  14.             for (int i=0; i<5; i++) {
  15.                 if (printable[i] instanceof Book) System.out.println("Только книги");
  16.             }
  17.         }
  18.     }
  19.  
  20.     public static class Magazine implements Printable {
  21.         public void print() {
  22.             System.out.println("Журнал");
  23.         }
  24.         public static void printMagazines(Printable[] printable) {
  25.             for (int i=0; i<5; i++) {
  26.                 if (printable[i] instanceof Magazine) System.out.println("Только журналы");
  27.             }
  28.         }
  29.     }
  30.  
  31.     public static void main(String[] args) {
  32.         Book PrestuplenieNakazanie = new Book();
  33.         Book ForWhomTheBellTools = new Book();
  34.         Book Steppenwolf = new Book();
  35.         Magazine NationalGeographic = new Magazine();
  36.         Magazine People = new Magazine();
  37.         Printable[] Paper = new Printable[] {PrestuplenieNakazanie,
  38.                 ForWhomTheBellTools, Steppenwolf, NationalGeographic, People};
  39.         for (int i=0; i<5; i++) {
  40.             Paper[i].print();
  41.         }
  42.         System.out.println();
  43.         Book.printBooks(Paper);
  44.         System.out.println();
  45.         Magazine.printMagazines(Paper);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement