Created
December 16, 2022 23:06
-
-
Save xvbnm48/7d13e9fac7e11b82a5ba17893d82c64e to your computer and use it in GitHub Desktop.
This is example OOP using Golang
This file contains hidden or 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" | |
// Kelas Mahasiswa dengan atribut nama dan jurusan | |
type Mahasiswa struct { | |
nama string | |
jurusan string | |
} | |
// Method untuk mengambil kelas Mahasiswa | |
func (m Mahasiswa) AmbilKelas() string { | |
return "Mahasiswa sedang mengambil kelas " + m.jurusan | |
} | |
func main() { | |
// Membuat objek Mahasiswa | |
mahasiswa1 := Mahasiswa{nama: "Andi", jurusan: "Teknik Informatika"} | |
// Menggunakan method AmbilKelas | |
fmt.Println(mahasiswa1.AmbilKelas()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment