<?class SA_class
{
function SA_class( $n="Mehdi" ,$a="20")//default name is "mehdi" and age is "20"
{
$this->name = $n;
$this->age=$a;
}
function sayHello()
{
print "Hello my name is $this->name and my age is $this->age <BR>";
}
}
$obj1 = new SA_class("Reza");
$obj2 = new SA_class("Ali","22");
$obj3 = new SA_class();
$obj1->sayHello();
// Hello my name is Reza and my age is 20
$obj2->sayHello();
// Hello my name is Ali and my age is 22
$obj3->sayHello();
// Hello my name is Mehdi and my age is 20
?>
سوال برنامه نویسی دارید؟
ندونستن عیب نیست، نپرسیدن چرا!