What is the output of the following program? package mainimp…

What is the output of the following program? package mainimport “fmt”import “time”func doSomething(s string) {    fmt.Println(s)}func main() {    go doSomething(“test 1”)    go doSomething(“test 2”)    fmt.Println(“main”)    time.Sleep(100 * time.Millisecond)}

Given the following Go code fragment: type Point struct {   …

Given the following Go code fragment: type Point struct {    X, Y float64} Write a code fragment that makes the Point struct implement  the built-in interface fmt.Stringer, assuming that the standard package fmt has been imported in the same package containing the given code fragment and your code fragment. The implementation must be done so that when calling fmt.Println to print an instance of Point, it will be printed in the following format: (X, Y)

Given the following Go program: package mainimport “fmt”type…

Given the following Go program: package mainimport “fmt”type T struct { S string }func (t *T) test(){ if t==nil { fmt.Println(“nil underlying value”) } else { fmt.Println(t.S)   }}type Test interface{ test()}var myTest Testfunc main(){ var t *T myTest = t myTest.test()} Which of the following statements is true about the given program?

Consider the following Go code fragment, assuming that varia…

Consider the following Go code fragment, assuming that variable any has been declared to be of the empty interface type.     if value, ok := any.(int); ok {        value = value + 2    } else if value, ok := any.(float64); ok {        value = value + 2.5    } else if value, ok := any.(string); ok {        value = value + “2”    } Rewrite the code fragment above as an equivalent type switch statement.

Complete the following Go code fragment so that the Balance…

Complete the following Go code fragment so that the Balance field in the Account struct is safe for use in concurrent program, i.e., only one goroutine can access the Account’s Balance at a time. Don’t type unnecessary whitespaces in your answers. Each blank you need to fill can contain no more than one statement. type Account struct{    guard_Balance [sync] //use this variable to guard Balance    Balance int32}func Update(acc Account,  amount int32){     [lock]     acc.Balance += amount     [unlock]}