Advertisement
jaVer404

level19.lesson10.home10(done)_some attempts

Feb 27th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package com.javarush.test.level19.lesson10.home10;
  2.  
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6.  
  7. /* Исправить ошибку
  8. Программа содержит всего 1 ошибку. Найди и исправь ее
  9. */
  10.  
  11. public class Solution {
  12.     {
  13.         System.out.println("it's Solution class");
  14.     }
  15.  
  16.     public static void main(String... args) throws IOException {
  17.         try (
  18.                 FileOutputStream outputStream = new FileOutputStream("c:/output.txt");
  19.                 InputStream is = Solution.class.getClassLoader().getResourceAsStream("/user/resources/avatar.gif");
  20.         ) {
  21.             ;
  22.             byte[] b = new byte[is.available()];
  23.             outputStream.write(is.read(b));
  24.  
  25.             int value = 123_456_789;
  26.             System.out.println(value);
  27.  
  28.             Example result = null;
  29.             String s = "a";
  30.             switch (s) {
  31.                 case "a": {
  32.                     result = new Solution().new A();
  33.                     break;
  34.                 }
  35.                 case "b": {
  36.                     result = new Solution().new B();
  37.                     break;
  38.                 }
  39.                 case "c": {
  40.                     result = new Solution().new C();
  41.                     break;
  42.                 }
  43.             }
  44.  
  45.             if (result instanceof A) {
  46.                 A p = (C) result;//!!!!!!!!!!!!!!!!!!!!ONE letter
  47.                 System.out.println(p.getClass().getSimpleName());
  48.             }
  49.  
  50.         } catch (IOException e) {
  51.         }
  52.     }
  53.  
  54.     interface Example {
  55.     }
  56.  
  57.     class A implements Example {
  58.         {
  59.             System.out.println("it's A class");
  60.         }
  61.     }
  62.  
  63.     class B implements Example {
  64.         {
  65.             System.out.println("it's B class");
  66.         }
  67.     }
  68.  
  69.     class C extends A {
  70.         {
  71.             System.out.println("it's C class");
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement