area calculated
This commit is contained in:
parent
db98168389
commit
2a2139caeb
2 changed files with 41 additions and 0 deletions
38
interfaces/demo1.go
Normal file
38
interfaces/demo1.go
Normal 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)
|
||||
}
|
3
main.go
3
main.go
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue