Php Abstract Class

A class which is defined with “abstract keyword” followed by class name is Known as Abstract class.

If a class has  at-least one abstract method then it becomes abstract class.

Abstract class can also contain non-abstract methods.

All methods can have public or protected access specifier.

It must for an abstract class to define the body of non-abstract method within abstract class.

we can not create instance of abstract class.

A class which extends abstract class, it is necessary to define all the methods which is declared in an abstract class.

The signature of the methods must be matched  which is defined in abstract class.

Abstract is an incomplete class, So in this way we can not create object of this class.

An Abstract class can have member variable ( properties ) and constants value.

we can not access  properties of abstract class because of incompleteness of class.

One abstract class can not be extends another abstract class.


<?php 
    
        abstract class Cars {
        
            public $a = 10;
            protected abstract function getCompanyName();
            public abstract function getPrice();
        }
        
        class Baleno  extends Cars {
        
            public function getCompanyName() {
              return "Marathi 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:
        Marathi Suzuki
	    720000
	    Hyundai
	    300000