Class
Sınıf Tanımlama
package main
import "fmt"
type King struct {
data int
}
func (a King) Add(x int) int {
return x + 5
}
func (a King) Result(x int) int {
return a.data + x
}
func main() {
var w King
fmt.Println(w.Add(3))
fmt.Printf("\n")
var y King = King{7}
fmt.Println(y.Result(3))
}
<?php
class King{
public $data=0;
public function __construct($i=0){
$this->data=$i;
}
public function Add($x){
$x=(int)$x;
return (int) ($x+5);
}
public function Result($x){
$x=(int)$x;
return (int)$this->data+$x;
}
}
$w=new King();
echo $w->Add(3);
echo "\n";
$y=new King(7);
echo $y->Result(3);
?>