Advertisement
jaVer404

level15.lesson02.task03

Jul 2nd, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. package com.javarush.test.level15.lesson02.task03;
  2.  
  3. /* ООП - машинки
  4. 1. Для вывода использовать можно только переменные из класс Constants.
  5. 2. В классе Ferrari реализуйте метод printlnDesire, чтобы он выводил на экран "Я хочу ездить на Феррари".
  6. 3. В классе Lanos реализуйте метод printlnDesire, чтобы он выводил на экран "Я хочу ездить на Ланосе".
  7. 4. Создайте public static класс LuxuriousCar(РоскошнаяМашина).
  8. 5. Создайте public static класс CheapCar(ДешеваяМашина).
  9. 6. Унаследуйте Ferrari и Lanos от CheapCar и LuxuriousCar, подумайте, какой класс для кого.
  10.  
  11. 7. В классе LuxuriousCar реализуйте метод printlnDesire, чтобы он выводил на экран "Я хочу ездить на роскошной машине".
  12. 8. В классе CheapCar реализуйте метод printlnDesire, чтобы он выводил на экран "Я хочу ездить на дешевой машине".
  13. 9. В класах LuxuriousCar и CheapCar для метода printlnDesire расставьте различными способами модификаторы доступа так,
  14. чтобы в классах Ferrari и Lanos выполнялось расширение видимости.
  15. */
  16.  
  17. public class Solution
  18. {
  19.     public static void main(String[] args)
  20.     {
  21.         new Solution.LuxuriousCar().printlnDesire();
  22.         new Solution.CheapCar().printlnDesire();
  23.         new Solution.Ferrari().printlnDesire();
  24.         new Solution.Lanos().printlnDesire();
  25.     }
  26.  
  27.     public static class Ferrari extends LuxuriousCar
  28.     {
  29.         public void printlnDesire()
  30.         {
  31.             //add your code here
  32.             System.out.println(Constants.WANT_STRING + Constants.FERRARY_NAME);
  33.         }
  34.     }
  35.  
  36.     public static class Lanos extends CheapCar
  37.     {
  38.         public void printlnDesire()
  39.         {
  40.             //add your code here
  41.             System.out.println(Constants.WANT_STRING + Constants.LANOS_NAME);
  42.         }
  43.     }
  44.  
  45.     public static class Constants
  46.     {
  47.         public static String WANT_STRING = "Я хочу ездить на ";
  48.         public static String LUXURIOUS_CAR = "роскошной машине";
  49.         public static String CHEAP_CAR = "дешевой машине";
  50.         public static String FERRARY_NAME = "Феррари";
  51.         public static String LANOS_NAME = "Ланосе";
  52.     }
  53.  
  54.     public static class LuxuriousCar
  55.     {
  56.         protected void printlnDesire()
  57.         {
  58.             //add your code here
  59.             System.out.println(Constants.WANT_STRING + Constants.LUXURIOUS_CAR);
  60.         }
  61.  
  62.     }
  63.     public static class CheapCar{
  64.         void printlnDesire() {
  65.             //add your code here
  66.             System.out.println(Constants.WANT_STRING + Constants.CHEAP_CAR);
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement