Kata of the Day #11

Creating a class

kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
Kata of the Day #11

Create a simple class on different programming languages.

TypeScript


class MyClass {
  private message: string = '';

  public setMessage(message: string) {
    this.message = message;
  }

  public getMessage() {
    return this.message;
  }
}

const myClass = new MyClass();
myClass.setMessage("My message");

console.log(myClass.getMessage());

Go


package main

import "fmt"

type MyClass struct {
    message string
}

func (c *MyClass) setMessage(message string) {
    c.message = message
}

func (c *MyClass) getMessage() string {
    return c.message
}

func main() {
    myClass := MyClass{}
    myClass.setMessage("My message")
    fmt.Println(myClass.getMessage())
}

Python


class MyClass:
    def __init__(self):
        self.message = ''

    def set_message(self, message):
        self.message = message

    def get_message(self):
        return self.message

my_class = MyClass()
my_class.set_message("My message")

print(my_class.get_message())

PHP


class MyClass {
    private $message = '';

    public function setMessage($message) {
        $this->message = $message;
    }

    public function getMessage() {
        return $this->message;
    }
}

$my_class = new MyClass();
$my_class->setMessage("My message");

echo $my_class->getMessage();

ByCesar Kohl

Need some help?

Want us to give you some help with your business? No problem, here's a video on who we can help, and how, along with our calendar so you can book in a call to discuss us working together.

Let's see
budget
budget
budget
budget
budget
budget
budget
budget
budget
budget

Subscribe to our newsletter

subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe