<?php
//1. When encapsulating a class, it is generally safe to use the protected property protected for encapsulation
//2. Methods for calling parent classes by subclasses
//(1). The parent class method property should take public or protected properties protected
//(2). Private properties can only be accessed in this class
//3. Subclasses can override methods that do not require a parent class method to overwrite
//4. When a subclass overrides a parent class method or field, what happens when it is called?
//Call Method Parent class Name:: Method () or Parent:: Method ()
The //5.final keyword prevents classes from being inherited, and separate classes must use this keyword when they do not want to be integrated with other classes, and it is best to add this keyword
//Keywords
//1.public Public property class itself and subclass are accessible
///2.private The Private property class itself can be accessed
///3.protected The protected attribute class itself and subclasses are accessible (typically used for this property for security purposes)
//4.extends Inheritance (PHP does not support multilayer inheritance, a class can inherit only one base class)
header (' content-type:text/html;charset= ' Utf-8 "');
//Define a parent class
class Computer
{
//public public properties, which can be called by the parent class child class
//private private properties, which cannot be inherited by the quilt class, the protected adornments are applied to encapsulate
//protected protected Property The parent subclass subclass can be called
Public $name = ' Gaofei ';
//Define a method
Public function say ()
{
return "My name is". $this->name;
}
}
//define a subclass
class Notecomputer extends computer
{
The //subclass does not require the fields and methods of the parent class, overrides the parent class with overridden methods, and so on fields
Public $name = ' James ';
Public function say ()
{
echo Computer::say ();
echo "My name is". $this->name;
//Call the parent class method that has been overridden
}
}
//Instantiation of Class
$obj = new Notecomputer ();
//echo $obj->say ();
//Plus keyword final The subclass cannot inherit the parent class.
Final class Pad
{
Public $data = ' 123 ';
}
class Pad_pro extends Pad
{
Public function say ()
{
return $this->data;
}
}
A summary of some knowledge points for the inheritance of PHP classes