Created
January 20, 2021 11:13
-
-
Save afrinjamanbd/a516ffaf3f887fb4772cc11949c5a157 to your computer and use it in GitHub Desktop.
This piece of code shows inheritance in golang.
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 Animal struct{ | |
Name string | |
Tail bool | |
Leg int | |
} | |
type Dog struct{ | |
Animal | |
Bark bool | |
} | |
func main() { | |
Animalobj:= Animal{ | |
Name: "Chicken", | |
Tail: false, | |
Leg: 2, | |
} | |
fmt.Println("Animal name is", Animalobj.Name, "\nTotal leg", Animalobj.Leg, "\nHas Tail =", Animalobj.Tail) | |
Dogobj:= Dog{ | |
Animal: Animal{ | |
Name: "Dog", | |
Tail: true, | |
Leg: 4, | |
}, | |
Bark: true, | |
} | |
fmt.Println("\n\nAnimal name is", Dogobj.Name, "\nTotal leg", Dogobj.Leg, "\nHas Tail =", Dogobj.Tail, "\nBarks =", Dogobj.Bark) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment