Class and Object example

<?php
class person
{
public $age = 10;
}
$man = new person();
echo $man->age;
?>

Here, the class name is person and an object named man .. and the object is mentioned as a person.. that is the man object have all the characteristics that the class person contain.

Explaining class we can say , classes are group of objects. In the above example the class person can be a man or woman with some specific characteristics like age,height,face color etc. And each specific man is an object . that is i am an object i have age,height, face color

you can notice that i display the age outside of the class just for an example but its better to display such types into a function or method inside the class.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s