Definition:
Sample code:1
class pencilbox()
{
var $type;
function set_type($mytype)
{
$this->type=$mytype;
}
}
Explanation:
Sample code :2
class pencilbox()
{
var $type;
function set_type($mytype)
{
$this->type=$mytype;
}
function get_type()
{
return $this->type;
}
}
Explanation:
- Classes are user defined data types.
- Classes are collection of objects which are in similar datatype.
- We can create any number of objects under a single class.
- Class has 2 main parts
1.Properties:
Properties are nothing but simple variables.
2.Methods:
Methods are functions of classes,used to manipulate data/variables/properties.
Sample code:1
class pencilbox()
{
var $type;
function set_type($mytype)
{
$this->type=$mytype;
}
}
Explanation:
- Here we are creating a class with the name pencilbox .
- $type-Property
- function set_type($mytype)-Method
Sample code :2
class pencilbox()
{
var $type;
function set_type($mytype)
{
$this->type=$mytype;
}
function get_type()
{
return $this->type;
}
}
Explanation:
- Setter method is used to set a property.[function set_type($mytype)]
- Getter method is used to get a property [function get_type()]
- $this : is a builtin variable which points to the current. property.[$this->property name]
No comments:
Post a Comment