abstract abstract class learning

1 abstract class keyword abstract

Class 2 as long as there is a method is declared as abstract methods abstract, then this class must be declared as an abstract class

3 abstract method allows only method declarations and parameter list, does not allow the method body

4 abstract methods of uncertainty, it is prohibited to instantiate an abstract class, inherit keyword allows only extends to instantiate

5 subclass of abstract class must have all the abstract methods to achieve full abstract class

6 subclass members access restriction level must be equal to or less agreed abstract class, an abstract class is protected, for example, must be protected subclass is private or public allowed

7. The method of subclass parameters must exactly match the parameters of the abstract class method, but allows to increase the default parameters

Fruits {class abstract 
    // Name of fruit 
    protected $ name; 
    // abstract method 
    abstract public function EAT (); 
    // can not be directly instantiated although abstract class, but can still have constructors 
    public the __construct function () { 
        return 'abstract class constructor , automatic call <br> instantiation '; 
    } 
} 

// actual development should create a separate class for each class file 
class the extends the Apple Fruits { 
    protected $ name =' apple '; 
    public EAT function () { 
        return $ . this-> name 'can be eaten directly'; 
    } 
    // subclass constructors 
    public function the __construct () { 
        echo parent :: __ Construct (); 
    } 
} 
$ = new new Apple the Apple; 
echo $ apple-> eAT ();

  

Guess you like

Origin www.cnblogs.com/viczhang/p/11410545.html