Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zwierzeta;
- public class Zwierzeta {
- void odglos()
- {
- System.out.println("Zwierze wydaje odglos:");
- }
- public static void main(String[] args) {
- Zwierzeta[] zwierzaki = new Zwierzeta[]
- {
- new Zwierzeta(),
- new Pies(),
- new Kot(),
- new Krowa()
- };
- for(Zwierzeta z: zwierzaki)
- {
- z.odglos();
- }
- /*
- for(int i = 0; i< zwierzaki.length;i++)
- {
- Zwierzeta z = zwierzaki[i];
- z.odglos();
- }
- */
- }
- }
- //------------------------------------------------------------------------------------------------------------
- package zwierzeta;
- public class Pies extends Zwierzeta {
- void odglos()
- {
- System.out.println("Woof woof!");
- }
- }
- //------------------------------------------------------------------------------------------------------------
- package zwierzeta;
- public class Kot extends Zwierzeta {
- void odglos() {
- System.out.println("Miau miau!");
- }
- }
- //------------------------------------------------------------------------------------------------------------
- package zwierzeta;
- public class Krowa extends Zwierzeta {
- void odglos() {
- System.out.println("Muuu!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement