Tuesday 20 March 2012

CONSTRUCTOR

<html>
<head>
<title>Example:1</title>
</head>
<body>
<?php
class first_class
{
var $name;
function first_class($n ="anon")
{
$this->name = $n;
}
function sayHello()
{
print " Hello my name is $this->name <BR>";
}
}
$obj1 = new first_class("sateesh");
$obj2 = new first_class("bagadhi");
$obj1->sayHello();
$obj2->sayHello();
 ?>
</body>
</html>

OUTPUT
Hello my name is sateesh
Hello my name is bagadhi 

No comments:

Post a Comment