Go course

StructsQuiz: Structs

Go

Display

Theme

Structs · Quiz

Quiz: Structs

Test what you know about structs, nested structs, anonymous structs, embedding, and methods. Answer every question in the right-hand panel.

  1. Question 1 of 5What does the following code print?
    type Produk struct {
    	Nama  string
    	Harga int
    	Aktif bool
    }
    
    var p Produk
    fmt.Printf("%+v\n", p)
  2. Question 2 of 5What does the following code print?
    type Titik struct{ X, Y int }
    
    a := Titik{1, 2}
    b := a
    b.X = 10
    fmt.Println(a.X)
  3. Question 3 of 5Given the following definitions, which expression is valid for getting the name?
    type Akun struct {
    	Nama string
    }
    
    type Admin struct {
    	Akun
    	Level int
    }
    
    ad := Admin{Akun: Akun{Nama: "Rudi"}, Level: 2}
  4. Question 4 of 5What does the following code print?
    type Lampu struct{ Nyala bool }
    
    func (l Lampu) Hidupkan() {
    	l.Nyala = true
    }
    
    func main() {
    	var l Lampu
    	l.Hidupkan()
    	fmt.Println(l.Nyala)
    }
  5. Question 5 of 5When is an anonymous struct the best fit?