Advertisement
jaVer404

level13.lesson02.task06

May 18th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. package com.javarush.test.level13.lesson02.task06;
  2.  
  3. /* Баг в initializeIdAndName
  4. 1. Подумать, что в программе неправильно.
  5. 2. Вынести реализацию метода initializeIdAndName в класс User.
  6. 3. initializeIdAndName в классе User должен возвращать тип User.
  7. 4. Поправить программу, чтобы компилировалась и работала.
  8. */
  9.  
  10. public class Solution
  11. {
  12.     public static void main(String[] args) throws Exception
  13.     {
  14.         System.out.println(Matrix.NEO);
  15.         System.out.println(Matrix.TRINITY);
  16.     }
  17.  
  18.     static class Matrix
  19.     {
  20.         public static DBObject NEO = new User().initializeIdAndName(1, "Neo");
  21.         public static DBObject TRINITY = new User().initializeIdAndName(2, "Trinity");
  22.     }
  23.  
  24.     interface DBObject
  25.     {
  26.         DBObject initializeIdAndName(long id, String name);
  27.     }
  28.  
  29.     static class User implements DBObject
  30.     {
  31.         long id;
  32.         String name;
  33.         public DBObject initializeIdAndName(long id, String name) {
  34.             this.id = id;
  35.             this.name = name;
  36.             return this;
  37.         }
  38.  
  39.         @Override
  40.         public String toString()
  41.         {
  42.             return String.format("User has name %s, id = %d", name, id);
  43.         }
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement