Advertisement
programajster

Z5_Zwierze

Mar 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package zwierzeta;
  2.  
  3. public class Zwierzeta {
  4.  
  5.     void odglos()
  6.     {
  7.         System.out.println("Zwierze wydaje odglos:");
  8.     }
  9.    
  10.     public static void main(String[] args) {
  11.  
  12.        Zwierzeta[] zwierzaki = new Zwierzeta[]
  13.        {
  14.            new Zwierzeta(),
  15.            new Pies(),
  16.            new Kot(),
  17.            new Krowa()                      
  18.        };
  19.    
  20.      
  21.     for(Zwierzeta z: zwierzaki)
  22.     {
  23.         z.odglos();
  24.     }
  25.        
  26.     /*
  27.     for(int i = 0; i< zwierzaki.length;i++)
  28.     {
  29.     Zwierzeta z = zwierzaki[i];
  30.     z.odglos();
  31.     }
  32.    
  33.     */
  34.        
  35.     }
  36.  
  37. }
  38. //------------------------------------------------------------------------------------------------------------
  39. package zwierzeta;
  40.  
  41. public class Pies extends Zwierzeta {
  42.  
  43.     void odglos()
  44.     {
  45.         System.out.println("Woof woof!");
  46.     }
  47.        
  48. }
  49. //------------------------------------------------------------------------------------------------------------
  50. package zwierzeta;
  51.  
  52. public class Kot extends Zwierzeta {
  53.  
  54.     void odglos() {
  55.         System.out.println("Miau miau!");
  56.     }
  57. }
  58. //------------------------------------------------------------------------------------------------------------
  59. package zwierzeta;
  60.  
  61. public class Krowa extends Zwierzeta {
  62.  
  63.     void odglos() {
  64.         System.out.println("Muuu!");
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement