olexander_dan

Untitled

Apr 24th, 2020
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. package com.learning;
  2.  
  3. abstract class Smartphone {
  4.  
  5.    protected final String name;
  6.  
  7.    public Smartphone(String name) {
  8.        this.name = name;
  9.    }
  10.  
  11.    public String getName() {
  12.        return name;
  13.    }
  14. }
  15.  
  16. class Iphone extends Smartphone {
  17.    public Iphone() {
  18.        super("Iphone");
  19.    }
  20. }
  21.  
  22. class Nokia extends Smartphone {
  23.    public Nokia() {
  24.        super("Nokia");
  25.    }
  26. }
  27.  
  28. interface SmartphoneProducer {
  29.    Smartphone produce();
  30. }
  31.  
  32. final class ChinaProducer implements SmartphoneProducer {
  33.    public Smartphone produce() {
  34.        return new Iphone();
  35.    }
  36. }
  37.  
  38. final class NonExistentProducer implements SmartphoneProducer {
  39.    public Smartphone produce() {
  40.        return new Nokia();
  41.    }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment