Friday, February 21, 2014

PHP oops Hybrid Inheritance Example



class GrandFather
{
	public function pocketMoney()
	{
		return  'Take this 1000 $';
	}

}


class Father extends GrandFather
{
	public function myIncome()
	{
		echo "My father told ".parent::pocketMoney();
	}
	
	public function myExpense()
	{
		return 'Take this 500 $
'; } } class Elder extends Father { public function myEarning() { echo "Father told me ".parent::myExpense(); } } class Younger extends Father { public function myEarning() { echo "Father told me ".parent::myExpense(); } } $elder = new Elder(); $elder->myEarning(); // output Father told me Take this 500 $ $younger = new Younger(); $younger->myEarning(); // output Father told me Take this 500 $

1 comment: