dongyuchen0214 2016-09-25 08:15
浏览 27
已采纳

什么是PHP中的抽象类? [重复]

This question already has an answer here:

I've been searching around but i cant seem to understand it. Can someone explain what exactly is an abstract class in php?

abstract class theClass {
}

I know the syntax but does it really do?

</div>
  • 写回答

1条回答 默认 最新

  • dongshan7708 2016-09-25 08:17
    关注

    Abstract Class – In PHP, these two features of object-oriented programming are used very frequently. Abstract classes that can't be instantiated rather they can be inherited. The class that inherits an abstract class can also be another abstract class. In PHP we can create an abstract class by using the keyword – 'abstract'.

    Listing 5 – Sample code for Abstract Class

    abstract class testParentAbstract {
        public function myWrittenFunction() {
            // body of your funciton
        }
    }
    
    class testChildAbstract extends testParentAbstract {
        public function myWrittenFunctioninChild() {
            // body of your function
        }
    }
    

    In the above example, we can create an instance of the child class – testChildAbstract, but we can't create the instance of the parent class – testParentAbstract. As we see that the child class is extending the parent class, we can use the property of the parent class in the child class. We can also implement an abstract method in our child class as per our need.

    Source . http://www.phpbuilder.com/articles/application-architecture/object-oriented/advanced-object-oriented-programming-in-php.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?