Page 327 - Computer Software Application TP - Volume 1
P. 327

COMPUTER SOFTWARE APPLICATION - CITS




                       $person1 = new Person();
                       //Access and Set Properties
                       $person1->name = “Bob”;
                       $person1->age = 25;
                       //Call Methods

                       $person1->greet();  // Output: Hello, my name is Bob.
                           ?>
                 </body>
                 </html>

           3  Save the program in C:\Apache24\htdocs in a folder with .php extension
           4   Run the Apache services from windows services
           5   Open the browser and type the following address
                                  http://localhost/foldername/
           6   Click the php file to run and verify the output.















           TASK 2: Object constructors
           1  Open the text editor
           2  Write the following codes

                    <html >
           <head>
                <title> constructors</title>
           </head>
           <body>

                  <?php


               class MyClass
               {

                       // Properties
                       public $name;
                       public $age;
                       // Constructor
                       public function __construct($name, $age)
                       {





                                                           312

                               CITS : IT & ITES - Computer Software Application - Exercise 59
   322   323   324   325   326   327   328   329   330   331   332