Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP OOP - Inheritance

<?php
class Fruit {
  public $name;
  public $color;
  public function __construct($name, $color) {
    $this->name = $name;
    $this->color = $color;
  }
  public function intro() {
    echo "The fruit is {$this->name} and the color is {$this->color}.";
  }
}

// Strawberry is inherited from Fruit
class Strawberry extends Fruit {
  public function message() {
    echo "Am I a fruit or a berry? ";
  }
}
$strawberry = new Strawberry("Strawberry", "red");
$strawberry->message();
$strawberry->intro();
?>
Comment

PREVIOUS NEXT
Code Example
Php :: how to create route in laravel 
Php :: cases_sensitive 
Php :: PHP substr_replace — Replace text within a portion of a string 
Php :: Detect Mobile Platform On Php 
Php :: laravel follow and unfollow relationship 
Php :: php typecast class 
Php :: Php OOP function CRUD 
Php :: laravel all 
Php :: laravel link to css or image 
Php :: php wait for exec to finish 
Php :: php 8 Match Expression / Switch Case 
Php :: substr_count excact match php 
Php :: comment installer laravel avec docker 
Php :: reset admin password magento 2 
Php :: php array 
Php :: create seed file from db laravel 
Php :: php glue strings 
Php :: create an email addresses php 
Php :: laravel with select 
Php :: Write Multi-Line Strings in PHP 
Php :: php qrcode 
Php :: php code generator 
Php :: double in php 
Php :: laravel debugbar not showing 
Php :: include vendor/autoload.php 
Php :: hide category menu from custom post type 
Php :: sample test tinker php artisan 
Php :: laravel collection tap 
Php :: file_get_contents max_execution_time 
Php :: mysql php update sum same table 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =