Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Tier
- {
- protected String laut;
- public abstract void gibLaut();
- }
- public class Vogel extends Tier
- {
- protected String laut = "Zwitschert";
- public Vogel()
- {
- }
- public Vogel(String laut)
- {
- this.laut = laut;
- }
- public void gibLaut()
- {
- System.out.println("Vogel: " + laut);
- }
- }
- public class Ente extends Vogel
- {
- protected String laut = "Zwitschert nicht";
- public Ente()
- {
- }
- public Ente(String laut)
- {
- this.laut = laut;
- // super(laut);
- }
- public void gibLaut()
- {
- System.out.println("Ente: " + laut);
- }
- public void gibLaut2()
- {
- super.gibLaut();
- }
- public static void main(String[] args)
- {
- Tier einTier = new Ente("quakt");
- einTier.gibLaut();
- //
- // Vogel einVogel = (Vogel) einTier;
- // einVogel.gibLaut();
- // Vogel einVogel = new Vogel();
- Ente eineEnte = (Ente) einTier;
- eineEnte.gibLaut();
- eineEnte.gibLaut2();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement