<?php
###########################################################################
interface fruit_i {
#var $color =""; #Fatal error: Interfaces may not include member variables
#function eatme(){}; #Fatal error: Interface function fruit_i::eatme() cannot contain body
function eatme();
function buyme();
function goodat();
}
class mango_i implements fruit_i {
function eatme(){ echo "Eat me! I\"m so sweet" ."\n <br>";}
function buyme(){ echo "you can buy me direcly from farm"."\n <br>";}
function goodat(){ echo "I\"m good at proteins" ."\n <br>" ;}
}
###########################################################################
abstract class fruit_a {
var $color ="";
function __construct(){}
function eatme(){}
function buyme(){ echo "You can me directly from farm" ."\n <br>" ;}
function goodat(){ echo "I\"m good at proteins" ."\n <br>" ;}
}
class mango_a extends fruit_a {
function __construct(){ echo "My color is ".$this->color."\n <br>"; }
function eatme(){ echo "Eat me! I\"m so sweet and delicious" ."\n <br>";}
function goodat(){ echo "I\"m good at proteins and natural minerals" ."\n <br>" ;}
function __destruct(){ echo "My color is ".$this->color."\n <br>";}
}
###########################################################################
#$apple = new fruit_i; # Fatal error: Cannot instantiate interface fruit_i
#$apple = new fruit_a; # Fatal error: Cannot instantiate abstract class fruit_a
$malgova = new mango_i ;
$malgova->eatme(); #Eat me! I"m so sweet
$malgova->buyme(); #you can buy me direcly from farm
$malgova->goodat(); #I"m good at proteins
unset($malgova);
echo "<br>";
$malgova = new mango_a ; ### Calling __construct() ### My color is [No color!]
$malgova->color = "Yellowish";
$malgova->eatme(); #Eat me! I"m so sweet and delicious
$malgova->buyme(); #You can me directly from farm
$malgova->goodat(); #I"m good at proteins and natural minerals
unset($malgova); ### Calling __destruct() ### My color is Yellowish
?>
Return to Kesavan Muthuvel's home page. Please send comments on these web pages to hi@kesavan.info (or) Feedback here CopyLeft (Ͻ) 2008 - 2023 Kesavan Muthuvel More on CopyLeft |