Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- </php
- abstract class Shape {
- private $x=0;
- private $y=0;
- private $z=0;
- public abstract function volume(){
- }
- }
- class rectangular extends shape {
- function __construct ($x,$y,$z){
- $this->x= $x;
- $this->y= $y;
- $this->z= $z;
- }
- function volume(){
- volume=$this->x*$this->y*$this->z;
- return volume;
- }
- }
- class cube extends shape {
- function __construct ($x){
- $this->x= $x;
- }
- function volume(){
- volume=$this->x*$this->x*$this->x;
- return volume;
- }
- }
- class sphere extends shape {
- function __construct($x){
- $this->x= $x;
- }
- function volume(){
- volume=4/3*pi()*$this->x*$this->x*$this->x;
- return volume;
- }
- }
- $shape =array(
- new rectangular(3,5,6),
- new cube(4),
- new sphere(8)
- );
- foreach ($shape as $shape1){
- echo $shape1-> volume(). "\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement