PHP abstract class to inherit the attention point of abstract class, object-oriented learning

Source: Internet
Author: User
Abstract classes cannot override abstract methods of abstract parent classes when they inherit another abstract class。 This usage can be understood as an extension of the abstract class.

The following example shows that an abstract class inherits from another abstract class and does not need to override the abstract method.

<?abstract class User {    protected $sal = 0;       Abstract function getsal ();    Abstract function Setsal ($sal);  } Abstract class Vipuser extends User {    }?>

Abstract classes cannot be overridden after they are inherited by an abstract method. If a rewrite occurs, the system will error.

<?abstract class User {    protected  $sal = 0;       Abstract function getsal ();    Abstract function Setsal ($sal);} Abstract class Vipuser extends User {    abstract function setsal ();}? >

Program Run Result:

Fatal Error:can ' t inherit abstract function User::setsal () (previously declared abstract in Vipuser) in E:\PHPProjects\te st.php on line 14


Conclusion: Abstract classes inherit abstract classes to extend the abstract class.

<?abstract class User {    protected $sal = 0;       Abstract function getsal ();    Abstract function Setsal ($sal);} Abstract class Vipuser extends User {    protected $commision = 0;    Static abstract function getcommision ();    Abstract function setcommision ();   }? >

The code above extends the method of the parent class

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.