Define an interface which has methods area( ), volume( ). Define constant PI. Create a class cylinder which implements this interface and calculate area and volume||EasyCoding45

In this Tutorial , we are going to learn how we can Define an interface which has methods area( ), volume( ), variable constant PI. and also we are going to Create a class cylinder which will implement the interface and calculating area and volume for the Cylinder.


Program ::--



<html>

<form method=get action="A2.php">

Enter Radius :<input type=text name=t1><br>

Enter Height :<input type=text name=t2><br>

<input type=submit value=calculate>

</form>

</html>

<?php

$radius=$_GET['t1'];

$height=$_GET['t2'];


interface shape

{

function area($r,$h);

function volume($r,$h);

}

class cylinder implements shape

{

const pi=3.14;

public $area=null;

public $volume=null;

function area($r,$h)

{

$this->area=2*self::pi*$r*$h+2*self::pi*$r*$r;

echo "Area of Cylinder is :$this->area<br> ";

}

function volume($r,$h)

{

$this->volume=2*self::pi*$r*$r;

echo "Volume of Cylinder is :$this->volume";

}

}

$obj=new cylinder();

$obj->area($radius,$height);

$obj->volume($radius,$height);

?>


Output ::--




                                    Thank You💚                            


Comments