Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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 calling abstract static function from inside abstrac class

abstract class AbstractFoo{
    public static function foo() {
        throw new RuntimeException("Unimplemented");
    }
    public static function getFoo(){
        return static::foo();
    }
}

class ConcreteFoo extends AbstractFoo{
    public static function foo(){
        return "bar";
    }
}

echo ConcreteFoo::getFoo();
Comment

php abstract class static method

Answer
  https://stackoverflow.com/questions/41611058/why-does-php-allow-abstract-static-functions/41611876
Comment

PREVIOUS NEXT
Code Example
Php :: route 
Php :: Email "" does not comply with addr-spec of RFC 2822. 
Php :: php in browser 
Php :: how to grab shortcode from custom post type 
Php :: how to refresh migration in laravel without losing data 
Php :: recorrer un array php 
Php :: wpdb count 
Php :: doctrine update entity 
Php :: add method to laravel blade 
Php :: ERROR: The following modules depend on mpm_prefork and need to be disabled first: php7.2 
Java :: javafx vm arguments 
Java :: java stack char 
Java :: java console text color 
Java :: make javafx open full screen 
Java :: full screen in jframe 
Java :: java pause 1 second 
Java :: starting code of java 
Java :: java check if able to parse int 
Java :: Could not initialize class org.apache.maven.plugin.war.util.WebappStructureSerializer 
Java :: java file dialog 
Java :: spigot how to make an inventory 
Java :: max long 
Java :: apk full form 
Java :: foreground java jframe 
Java :: java get monitor size 
Java :: android back navigation 
Java :: Could not initialize class org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt 
Java :: java jlabel border 
Java :: list of longs to comma separeated string java 
Java :: java mouselistener get coordinates 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =