-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
81 lines (56 loc) · 2.09 KB
/
Solution.java
File metadata and controls
81 lines (56 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.javarush.task.task14.task1401;
//He who observes the day, observes it to the Lord; and he who does not observe the day, to the Lord he does not observe it.
//He who eats, eats to the Lord, for he gives God thanks. He who doesn't eat, to the Lord he doesn't eat,
//and gives God thanks. (Romans 14:6)
/*
Bingo!
*/
public class Solution {
public static void main(String[] args) {
Object animal = new Tiger();
boolean isCat = animal instanceof Cat;
boolean isTiger = animal instanceof Tiger;
boolean isPet = animal instanceof Pet;
printResults(isCat, isTiger, isPet);
}
private static void printResults(boolean cat, boolean tiger, boolean pet) {
if (cat && tiger && pet) System.out.println("Bingo!");
}
static class Pet {
}
static class Cat extends Pet {
}
static class Tiger extends Cat {
}
}
/*
Bingo!
Исправь строчку ‘Object animal = new Pet();‘ в методе main так, чтобы программа вывела «Bingo!«.
Требования:
1. Класс Cat должен наследоваться от класса Pet.
2. Класс Tiger должен наследоваться от класса Cat.
3. В переменной animal должен храниться объект который будет одновременно являться и Pet, и Cat, и Tiger.
4. Программа должна выводить на экран: "Bingo!".
package com.javarush.task.task14.task1401;
*
Bingo!
*
public class Solution {
public static void main(String[] args) {
Object animal = new Pet();
boolean isCat = animal instanceof Cat;
boolean isTiger = animal instanceof Tiger;
boolean isPet = animal instanceof Pet;
printResults(isCat, isTiger, isPet);
}
private static void printResults(boolean cat, boolean tiger, boolean pet) {
if (cat && tiger && pet) System.out.println("Bingo!");
}
static class Pet {
}
static class Cat extends Pet {
}
static class Tiger extends Cat {
}
}
*/