Page 331 - Computer Software Application TP - Volume 1
P. 331
COMPUTER SOFTWARE APPLICATION - CITS
private $radius;
public function __construct($radius)
{
$this->radius = $radius;
}
public function getArea()
{
return MathConstants::PI * $this->radius * $this->radius;
}
}
$con= new MathConstants();
$con->printConstants()
$circle = new Circle(5);
echo “Area of circle is:”. $circle->getArea(); // Output: 78.53975
?>
</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: Using class inheritance
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Class inheritance </title>
</head>
<body>
<?php
316
CITS : IT & ITES - Computer Software Application - Exercise 60