Abstract Classes:
<?php
abstract class Cars {
public abstract function getCompanyName();
public abstract function getPrice();
}
class Baleno extends Cars {
public function getCompanyName() {
return "Maruti Suzuki" . "<br/>";
}
public function getPrice() {
return 720000 . "*<br/>";
}
}
class Santro extends Cars {
public function getCompanyName() {
return "Hyundai" . "<br/>";
}
public function getPrice() {
return 300000 . "*<br/>";
}
}
$car = new Baleno();
$car1 = new Santro();
echo $car->getCompanyName();
echo $car->getPrice();
echo $car1->getCompanyName();
echo $car1->getPrice();
?>
Output
Maruti Suzuki
720000*
Hyundai
300000*
Note: Abstract classes:
Abstract class | Interface |
It can have constants, members, method stubs (methods without a body), methods | It can only have constants and methods stubs. |
Methods and members can have public or protected visibility
| Methods of the interface should only be public not any other visibility |
The concept of multiple inheritances not supported.
| An interface can extend or a class can implement multiple other interfaces. |
Child class must implement all the abstract methods of parent class when extend keyword is used.
| No need of implementing methods from parent interface when interface is extending another interface |
© 2025 Easy To Learning. All Rights Reserved | Design by Easy To Learning