Creating a class
Create a simple class on different programming languages.
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());
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())
}
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())
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();
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