Page 334 - Computer Software Application TP - Volume 1
P. 334
COMPUTER SOFTWARE APPLICATION - CITS
{
parent::__construct($name);
$this->radius = $radius;
}
// Implementing abstract method
public function calculateArea()
{
return pi() * pow($this->radius, 2);
}
}
// Concrete subclass of Shape
class Square extends Shape
{
private $side;
public function __construct($name, $side)
{
parent::__construct($name);
$this->side = $side;
}
// Implementing abstract method
public function calculateArea()
{
return pow($this->side, 2);
}
}
// Creating instances of concrete subclasses
$circle = new Circle(“Circle”, 5);
$square = new Square(“Square”, 4);
// Calling methods on instances
echo”Area of circle is :”.$circle->calculateArea(); // Output: 78.539816339745
echo “<br/>”;
echo”Area of square is :”.$square->calculateArea(); // Output: 16
?>
</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
319
CITS : IT & ITES - Computer Software Application - Exercise 60 CITS : IT & ITES - Computer Software Application - Exercise 60