Created
June 29, 2014 17:44
-
-
Save bolilla/8e8570533225a05b082b to your computer and use it in GitHub Desktop.
GoPadawan OO Ejemplo Clasico
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type rectángulo struct { | |
lado1, lado2 float32 | |
} | |
func (r rectángulo) área() float32 { | |
return r.lado1 * r.lado2 | |
} | |
func (r rectángulo) perímetro() float32 { | |
return (2 * r.lado1) + (2 * r.lado2) | |
} | |
func main() { | |
var miRectángulito rectángulo = rectángulo{3.0, 4.0} | |
fmt.Println("Este es mi rectángulo", miRectángulito) | |
fmt.Println("¡Hay otros muchos, pero este es el mío!") | |
fmt.Println("Su área es", miRectángulito.área()) | |
fmt.Println("Su perímetro es", miRectángulito.perímetro()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment