We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
0 parents commit adcf760Copy full SHA for adcf760
interfaces/shape/main.go
@@ -0,0 +1,41 @@
1
+package main
2
+
3
+import "fmt"
4
5
+type triangle struct {
6
+ height float64
7
+ base float64
8
+}
9
10
+type square struct {
11
+ sideLength float64
12
13
14
+type shape interface {
15
+ getArea() float64
16
17
18
+func main() {
19
+ tr := triangle{
20
+ height: 23,
21
+ base: 46,
22
+ }
23
+ sq := square{
24
+ sideLength: 44,
25
26
27
+ printArea(tr)
28
+ printArea(sq)
29
30
31
+func (s square) getArea() float64 {
32
+ return s.sideLength * s.sideLength
33
34
35
+func (t triangle) getArea() float64 {
36
+ return 0.5 * t.base * t.height
37
38
39
+func printArea(s shape) {
40
+ fmt.Println(s.getArea())
41
0 commit comments