-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0129d8e
commit 8c10643
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package simple | ||
|
||
import "fmt" | ||
|
||
type Plate struct { | ||
letters string | ||
numbers string | ||
} | ||
|
||
type Car struct { | ||
name string | ||
color string | ||
plate Plate | ||
} | ||
|
||
func Structs() { | ||
fmt.Println("Creating car...") | ||
|
||
car := Car{ | ||
name: "Honda Civic Type R", | ||
color: "red", | ||
plate: Plate{ | ||
letters: "ABC", | ||
numbers: "1234", | ||
}, | ||
} | ||
|
||
fmt.Println(car) | ||
|
||
car.color = "blue" | ||
|
||
fmt.Println("The car has been painted to the color: [", car.color, "]") | ||
|
||
//function | ||
showPlate(car.plate) | ||
|
||
//method | ||
car.displayPlate() | ||
} | ||
|
||
//function | ||
func showPlate(p Plate) { | ||
fmt.Print("\n" + p.letters + "-" + p.numbers + "\n") | ||
} | ||
|
||
//method - struct Car | ||
func (c Car) displayPlate() { | ||
fmt.Print("\n" + c.plate.letters + "-" + c.plate.numbers + "\n") | ||
} |