Skip to content

Commit 5151b39

Browse files
authored
Переопредели метод getName в классе Cat
For some thought, because Judas had the money box, that Jesus said to him, "Buy what things we need for the feast," or that he should give something to the poor. (John 13:29)
1 parent 9ea356b commit 5151b39

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

‎task12/task1221/Solution.java‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.javarush.task.task12.task1221;
2+
3+
//For some thought, because Judas had the money box, that Jesus said to him, "Buy what things we need for the feast,"
4+
//or that he should give something to the poor. (John 13:29)
5+
6+
/*
7+
Все мы немного кошки…
8+
*/
9+
10+
public class Solution {
11+
public static void main(String[] args) {
12+
Pet pet = new Cat();
13+
14+
System.out.println(pet.getName());
15+
}
16+
17+
public static class Pet {
18+
public String getName() {
19+
return "Я - пушистик";
20+
}
21+
}
22+
23+
public static class Cat extends Pet {
24+
public String getName() {
25+
return "Я - кот";
26+
}
27+
}
28+
}
29+
30+
31+
32+
33+
/*
34+
Все мы немного кошки…
35+
Переопредели метод getName в классе Cat так, чтобы программа выдавала на экран надпись «Я - кот».
36+
37+
38+
Требования:
39+
1. Класс Solution должен содержать класс Pet.
40+
2. Класс Solution должен содержать класс Cat.
41+
3. Класс Cat должен наследоваться от класса Pet.
42+
4. Класс Pet должен содержать один метод getName().
43+
5. Класс Cat должен переопределять метод getName().
44+
6. Программа должна выводить на экран результат метода getName() объекта pet.
45+
46+
package com.javarush.task.task12.task1221;
47+
48+
49+
Все мы немного кошки…
50+
51+
52+
public class Solution {
53+
public static void main(String[] args) {
54+
Pet pet = new Cat();
55+
56+
System.out.println(pet.getName());
57+
}
58+
59+
public static class Pet {
60+
public String getName() {
61+
return "Я - пушистик";
62+
}
63+
}
64+
65+
public static class Cat extends Pet {
66+
67+
}
68+
}
69+
70+
*/

0 commit comments

Comments
 (0)