Abstract Class

An abstract class cannot be instantiated. In other words, it is not allowed to create a new instance of an abstract class. An abstract class can contain properties and methods.

<?php

abstract class Student{

	public $name;
	public $age;

	public function details(){

		return "My name is ".$this->name.". I am ".$this->age." years old <br/>";
	}

	abstract public function book();
}


class Boy extends Student{

	function describe(){

		return	parent::details()." and I am a college student <br/>";
	}

	public function book(){

		return "I like to read story book";
	}
	
}

$boy = new Boy;
$boy->name = "Faruk";
$boy->age = 18;
echo $boy->describe();
echo $boy->book();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s