Object-Oriented Development 5 abstract keywords abstract

Source: Internet
Author: User
Definition, which is equivalent to a specification. an abstract class cannot be instantiated. it can only be instantiated after being overloaded in a derived class. Abstract class: when at least one method in a class is an abstract method, it can be called an abstract class. abstract functions must be added before abstract methods and abstract classes. More importantly, they can be used as a standard and a ruler. If no abstract class is overloaded in the derived class, an error is returned.

Definition, which is equivalent to a specification. an abstract class cannot be instantiated. it can only be instantiated after being overloaded in a derived class.

Abstract class. an abstract class can be called only when at least one method in a class is an abstract method. abstract methods and abstract classes must be added before abstract methods.

It is used as a standard and a ruler. If no abstract class is overloaded in the derived class, an error is returned.

 
 
  1. Abstract class Cxclass {
  2. Abstract function Name ();
  3. Abstract function Stroe ();
  4. Abstract function Sex ();
  5. }
  6. Class Myclass extends Cxclass {
  7. Public $ name;
  8. Public $ stroe;
  9. Public $ sex;
  10. Function _ construct ($ name, $ stroe, $ sex ){
  11. $ This-> name = $ name;
  12. $ This-> stroe = $ stroe;
  13. $ This-> sex = $ sex;
  14. }
  15. Function Name (){
  16. Return "name". $ this-> name ."
    ";
  17. }
  18. Function Stroe (){
  19. Return "score". $ this-> stroe ."
    ";
  20. }
  21. Function Sex (){
  22. Return "gender". $ this-> sex ."
    ";
  23. }
  24. }
  25. $ Myclass = new Myclass ("small", 96, "male ");
  26. Echo $ myclass-> Name (). $ myclass-> Stroe (). $ myclass-> Sex ();
  27. ?>

Output result

Small name
Score 96
Gender Male

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.