Created
March 20, 2021 10:28
-
-
Save artturijalli/2c2aafd1fd46d3381fdbb6654b555d0b to your computer and use it in GitHub Desktop.
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" | |
// STRUCTURES - a collection of fields to construct a logical type | |
type Fruit struct { | |
name string | |
color string | |
} | |
// Create a method for the Fruit that prints info about the fruit | |
func (fruit Fruit) information(){ | |
fmt.Println("I am a", fruit.color, fruit.name) | |
} | |
func main() { | |
// Create a new Fruit, banana; | |
banana := Fruit{name:"Banana", color:"Yellow"} | |
// Use the Fruit method information to print info: | |
banana.information() // prints "I am a Yellow Banana" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment