博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
抽象类和接口的区别
阅读量:3986 次
发布时间:2019-05-24

本文共 416 字,大约阅读时间需要 1 分钟。

1、接口的作用比较单一,它只能定义一些待实现的方法,不能有成员属性,无法封装数据,也不能自己实现方法。

interface DemoInterface{    public function test1();    public function test2();}

其他类通过 implements 来实现接口的所有方法。

2、抽象类的功能更加丰富,可以定义待实现的方法,数据封装,自己实现一些方法。

abstract class RobotRepositoryInterface{	private $name;    abstract function searchForHot($hotBooks);    function getThirdCoverByIssn($request){    	echo 123;    }}

其他类通过继承的方式来继承抽象类的数据,已实现的方法,然后去实现待实现的方法,或者重写父类的方法。

转载地址:http://sgxui.baihongyu.com/

你可能感兴趣的文章
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]112. Path Sum
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]119. Pascal's Triangle II
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode BY Python]155. Min Stack
查看>>
[LeetCode By Python]167. Two Sum II - Input array is sorted
查看>>
[LeetCode By Python]168. Excel Sheet Column Title
查看>>
[LeetCode BY Python]169. Majority Element
查看>>
[LeetCode By Python]171. Excel Sheet Column Number
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
Mac删除文件&文件夹
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>
《Fluent Python》第三章Dictionaries and Sets
查看>>