Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package polimorfizm;
- class Pojazd
- {
- void jedzie()
- {
- System.out.println("Pojazd jedzie!");
- }
- }
- class Auto extends Pojazd
- {
- @Override
- void jedzie()
- {
- System.out.println("Auto jedzie!");
- }
- }
- class Rower extends Pojazd
- {
- @Override
- void jedzie()
- {
- System.out.println("Rower jedzie!");
- }
- }
- public class Polimorfizm {
- public static void main(String[] args) {
- Pojazd p1 = new Pojazd();
- Auto a1 = new Auto();
- Rower r1 = new Rower();
- Pojazd p2 = a1;
- Pojazd p3 = r1;
- p1.jedzie(); //pojazd
- a1.jedzie(); //auto
- r1.jedzie(); //rower
- p1.jedzie(); //pojazd
- p2.jedzie(); //auto
- p3.jedzie(); //rower
- p2 = p1;
- p3 = p1;
- p1.jedzie(); //pojazd
- p2.jedzie(); //pojazd
- p3.jedzie(); //pojazd
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement