Can a class extend both a class and implement an Interface

微笑、不失礼 提交于 2019-12-02 14:47:18

Try it the other way around:

class database extends mysqli implements databaseInterface { ...}

This should work.

Yes it can. You just need to retain the correct order.

class database extends mysqli implements databaseInterface { ... }

Moreover, a class can implement more than one interface. Just separate 'em with commas.

However, I feel obliged to warn you that extending mysqli class is incredibly bad idea. Inheritance per se is probably the most overrated and misused concept in object oriented programming.

Instead I'd advise doing db-related stuff the mysqli way (or PDO way).

Plus, a minor thing, but naming conventions do matter. Your class database seems more general then mysqli, therefore it suggests that the latter inherits from database and not the way around.

yes, in fact if you want to implement multiple interfaces you can do like this:

public class MyClass extends BaseClass implements myInterface1, myInterface2, myInterface3{ 

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!