|
| 1 | +package com.javarush.task.task14.task1406; |
| 2 | + |
| 3 | +//For it is written, "'As I live,' says the Lord, 'to me every knee will bow. Every tongue will confess to God.'" (Romans 14:11) |
| 4 | + |
| 5 | +/* |
| 6 | +Без ошибок |
| 7 | +*/ |
| 8 | + |
| 9 | +public class Solution { |
| 10 | + public static void main(String[] args) { |
| 11 | + Object obj = new Jerry();//Add your code here |
| 12 | + |
| 13 | + Mouse mouse = (Mouse) obj; |
| 14 | + GreyMouse greyMouse = (GreyMouse) mouse; |
| 15 | + Jerry jerry = (Jerry) greyMouse; |
| 16 | + |
| 17 | + printClasses(obj, mouse, greyMouse, jerry); |
| 18 | + |
| 19 | + } |
| 20 | + |
| 21 | + public static void printClasses(Object obj, Mouse mouse, GreyMouse greyMouse, Jerry jerry) { |
| 22 | + System.out.println(jerry.getClass().getSimpleName()); |
| 23 | + System.out.println(greyMouse.getClass().getSimpleName()); |
| 24 | + System.out.println(mouse.getClass().getSimpleName()); |
| 25 | + System.out.println(obj.getClass().getSimpleName()); |
| 26 | + } |
| 27 | + |
| 28 | + static class Mouse { |
| 29 | + } |
| 30 | + |
| 31 | + static class GreyMouse extends Mouse { |
| 32 | + } |
| 33 | + |
| 34 | + static class Jerry extends GreyMouse { |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +/* |
| 43 | +Без ошибок |
| 44 | +Инициализировать объект obj таким классом, чтобы метод main выполнился без ошибок. |
| 45 | +
|
| 46 | +
|
| 47 | +Требования: |
| 48 | +1. Класс GreyMouse должен наследоваться от класса Mouse. |
| 49 | +2. Класс Jerry должен наследоваться от класса GreyMouse. |
| 50 | +3. В переменной obj должен храниться объект который будет одновременно являться и Mouse, и GreyMouse, и Jerry. |
| 51 | +4. Метод main должен вызывать метод printClasses. |
| 52 | +
|
| 53 | +package com.javarush.task.task14.task1406; |
| 54 | +
|
| 55 | +* |
| 56 | +Без ошибок |
| 57 | +* |
| 58 | +
|
| 59 | +public class Solution { |
| 60 | + public static void main(String[] args) { |
| 61 | + Object obj = //Add your code here |
| 62 | +
|
| 63 | + Mouse mouse = (Mouse) obj; |
| 64 | + GreyMouse greyMouse = (GreyMouse) mouse; |
| 65 | + Jerry jerry = (Jerry) greyMouse; |
| 66 | +
|
| 67 | + printClasses(obj, mouse, greyMouse, jerry); |
| 68 | +
|
| 69 | + } |
| 70 | +
|
| 71 | + public static void printClasses(Object obj, Mouse mouse, GreyMouse greyMouse, Jerry jerry) { |
| 72 | + System.out.println(jerry.getClass().getSimpleName()); |
| 73 | + System.out.println(greyMouse.getClass().getSimpleName()); |
| 74 | + System.out.println(mouse.getClass().getSimpleName()); |
| 75 | + System.out.println(obj.getClass().getSimpleName()); |
| 76 | + } |
| 77 | +
|
| 78 | + static class Mouse { |
| 79 | + } |
| 80 | +
|
| 81 | + static class GreyMouse extends Mouse { |
| 82 | + } |
| 83 | +
|
| 84 | + static class Jerry extends GreyMouse { |
| 85 | + } |
| 86 | +} |
| 87 | +
|
| 88 | +*/ |
0 commit comments