area calculated

This commit is contained in:
Mert Gör 🇹🇷 2024-01-22 09:03:58 +03:00
parent db98168389
commit 2a2139caeb
Signed by: hwpplayer1
GPG Key ID: 03E547D043AB6C8F
2 changed files with 41 additions and 0 deletions

38
interfaces/demo1.go Normal file
View File

@ -0,0 +1,38 @@
package interfaces
import (
"fmt"
"math"
)
type shape interface{
area() float64
}
type rectangle struct{
rectangle_width, rectangle_height float64
}
type circle struct{
radius float64
}
func (r rectangle) area() float64{
return r.rectangle_height * r.rectangle_width
}
func (c circle) area() float64 {
return math.Pi * c.radius * c.radius
}
func school(s shape) {
fmt.Println("Area : ", s.area())
}
func Demo1() {
r:= rectangle{
rectangle_width: 10, rectangle_height: 6,
}
school(r)
}

View File

@ -8,6 +8,7 @@ import (
"golesson/examplerange"
"golesson/functions"
"golesson/goroutines"
"golesson/interfaces"
"golesson/loops"
"golesson/maps"
"golesson/pointers"
@ -75,4 +76,6 @@ func main() {
multiply := EvenNumberTotal * OddNumberTotal
fmt.Println("Multiply Result : ", multiply)
interfaces.Demo1()
}