Advertisement
spacerose

lab4(java)

Sep 6th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. //Priceable
  2.  
  3. public interface Priceable {
  4.     void getPrice();
  5. }
  6.  
  7. //Animal
  8.  
  9. public class Animal implements Priceable {
  10.  
  11.     int price;
  12.     String name;
  13.     boolean male;
  14.  
  15.     Animal(String name,int price,boolean male){
  16.         this.name=name;
  17.         this.price=price;
  18.         this.male=male;
  19.     }
  20.     @Override
  21.     public void getPrice() {
  22.         System.out.println("Animal: "+price);
  23.     }
  24.  
  25. }
  26.  
  27.  
  28. //Car
  29.  
  30. public class Car implements Priceable{
  31.  
  32.     int price;
  33.     String name;
  34.  
  35.     Car(String name,int price){
  36.         this.name=name;
  37.         this.price=price;
  38.  
  39.     }
  40.     @Override
  41.     public void getPrice() {
  42.         System.out.print("Car: "+price);
  43.     }
  44.  
  45. }
  46.  
  47. //MainApp
  48.  
  49. public class MainApp {
  50.     public static void main(String[] args) {
  51.  
  52.         Animal pet=new Animal("Cat",37,false);
  53.         Car vehicle=new Car("Tesla",666);
  54.  
  55.         pet.getPrice();
  56.         vehicle.getPrice();
  57.     }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement