File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ interface Color {
2
+ fun getColor ()
3
+ }
4
+
5
+ class Yellow : Color {
6
+ override fun getColor () {
7
+ println (" Yellow" )
8
+ }
9
+ }
10
+
11
+ class Red : Color {
12
+ override fun getColor () {
13
+ println (" Red" )
14
+ }
15
+ }
16
+
17
+ interface House {
18
+ val color: Color
19
+ fun show ()
20
+ }
21
+
22
+ class WoodHouse (override val color : Color ): House {
23
+ override fun show () {
24
+ print (" The wood house color is " )
25
+ color.getColor()
26
+ }
27
+ }
28
+
29
+ class RockHouse (override val color : Color ): House {
30
+ override fun show () {
31
+ print (" The rock house color is " )
32
+ color.getColor()
33
+ }
34
+ }
35
+
36
+ fun main () {
37
+ val yellowWoodHouse = WoodHouse (color = Yellow ())
38
+ yellowWoodHouse.show()
39
+ val yellowRockHouse = RockHouse (color = Yellow ())
40
+ yellowRockHouse.show()
41
+ val redWoodHouse = WoodHouse (color = Red ())
42
+ redWoodHouse.show()
43
+ val redRockHouse = RockHouse (color = Red ())
44
+ redRockHouse.show()
45
+ }
You can’t perform that action at this time.
0 commit comments