Search
 
SCRIPT & CODE EXAMPLE
 

PHP

what is abstract class in php with example

<?php
abstract class Cars
{
    abstract function car_details();
}
class Maruti extends Cars
{
    function car_details()
    {
        echo "Maruti Details";
    }
}
class Honda extends Cars
{
    function car_details()
    {
        echo "<br>Honda Details<br>";
    }
}

class Scoda extends Cars
{
    function car_details()
    {
        echo "<br>Scoda Details<br>";
    }
}

$obj = new Maruti();
$obj -> car_details();

$obj1 = new Honda();
$obj1 -> car_details();

$obj2 = new Scoda();
$obj2 -> car_details();
?>
Comment

what is abstract class in php


<?php
/**
 *Abstract Methods and Classes
 *An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
 *An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:
 
 *abstract void car_details(char model, double price);

 *If a class includes abstract methods, then the class itself must be declared abstract, as in:

 *	public abstract class Cars {
 *	   // declare fields
 *	   // declare nonabstract methods
 *	   abstract void car_details();
 *	}
 * When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract.

 * In Abstract class someone can write the definitation and someone can use/extend it, abstract means incomplete.
 * It is not possible to create object of abstract method
 * abstract class contains atleast 1 abstract function, it can have abstract and non abstract methods.
 * abstract function can not contain body or definitation it must declare, but should not have function definitation.
 * abstract class, child class must contain abstract function
 */
abstract class Cars
{
    abstract function car_details();
}
class Maruti extends Cars
{
    function car_details()
    {
        echo "Maruti Details";
    }
}
class Honda extends Cars
{
    function car_details()
    {
        echo "<br>Honda Details<br>";
    }
}

class Scoda extends Cars
{
    function car_details()
    {
        echo "<br>Scoda Details<br>";
    }
}

$obj = new Maruti();
$obj -> car_details();

$obj1 = new Honda();
$obj1 -> car_details();

$obj2 = new Scoda();
$obj2 -> car_details();
?>
Comment

PHP OOP - Abstract Classes

<?php
abstract class ParentClass {
  abstract public function someMethod1();
  abstract public function someMethod2($name, $color);
  abstract public function someMethod3() : string;
}
?>
Comment

PREVIOUS NEXT
Code Example
Php :: share to facebook from website laravel 
Php :: error handling in laravel 
Php :: laravel collection all 
Php :: laravel find 
Php :: latest php version 
Php :: laravel property 
Php :: how to create object in php 
Php :: open phpstorm from terminal 
Php :: Array (key and value) 
Php :: PHP Notice: Trying to get property of non-object 
Php :: phpexcel 
Php :: create orphan token in vault 
Php :: getDoctrine 
Php :: php how to check if user has a role on login 
Php :: how to convert amount in words in php 
Php :: php enc 
Php :: elasticsearch php filter range 
Php :: laravel nova create resource 
Php :: wordpress set category front end 
Php :: limit query laravel 
Php :: Initialisez un tableau de 4 cases (contenant des nombres) et en faire la somme en créant une fonction somme php 
Php :: php tools for visual studio package did not load correctly 
Php :: rename image file using post id in wordpress programmatically 
Php :: php artisan seading 
Php :: count letters in string without space or characters and numbers in php 
Php :: add selected to dropdpown item laravel 
Php :: how-to-add-pagination-in-search-results wordpress 
Php :: cant use migrate with sail laravel 
Php :: how to make:trait in commend line in laravel 
Php :: php crash course could not find driver 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =