Advertisement
Guest User

Untitled

a guest
May 30th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. public abstract class Pojazd{
  2.  
  3.      String imie;
  4.      String nazwisko;
  5.      String model;
  6.      int rejestracja;
  7.      
  8.      public Pojazd(String imie, String nazwisko, String model, int rejestracja){
  9.          this.imie=imie;
  10.          this.nazwisko=nazwisko;
  11.          this.model=model;
  12.          this.rejestracja=rejestracja;
  13.      }
  14.    
  15.      public static void main(String[] args){
  16.         Pojazd s1 = new Samochod("Jan","Kowalski","BMW","Czarny",54987);
  17.         Pojazd s2 = new Samochod("Krzysiek","Stachura","Nissan","Czerwony",12987);
  18.         Pojazd s3 = new Samochod("Lukasz","Kowalski","Peugeot","Niebieski",11987);
  19.         Pojazd s4 = new Samochod("Pawel","Ziom","Ford","ZOlty",33947);
  20.         Pojazd s5 = new Samochod("Damian","Jaro","Audi","Fioletowy",12987);
  21.         Pojazd m1 = new Motocykl("Krzysiek","Jarzyna","Kawasaki",12942);
  22.         Pojazd m2 = new Motocykl("Jarek","Bak","BMW",45987);
  23.         Pojazd m3 = new Motocykl("Adam","BezNazwiska","Yamaha",77987);
  24.         Pojazd m4 = new Motocykl("Piotrek","Kaczmarek","Suzuki",30987);
  25.         Pojazd m5 = new Motocykl("Wojtek","Kowalski","Honda",63917);
  26.      }
  27. }
  28.  
  29. public class Samochod extends Pojazd {
  30.     String kolor;
  31.     public Samochod(String imie, String nazwisko, String model, String kolor, int rejestracja) {
  32.         super(imie, nazwisko, model, rejestracja);
  33.         this.kolor=kolor;  
  34.     }
  35.     public String toString(){
  36.         String s = "Imie: "+imie+"\nNazwisko: "+nazwisko+"\nModel samochodu: "+model+"\nKolor: "+kolor+"\nRejestracja:
  37.  
  38. "+rejestracja;
  39.         return s;
  40.     }
  41. }
  42. public class Motocykl extends Pojazd {
  43.     public Motocykl(String imie, String nazwisko, String model, int rejestracja){
  44.         super(imie,nazwisko,model,rejestracja);
  45.     }
  46.     public String toString(){
  47.         String s = "Imie: "+imie+"\nNazwisko: "+nazwisko+"\nModel motocykla: "+model+"\nRejestracja: "+rejestracja;
  48.         return s;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement