One 、 Other syntax for interfaces
I talked about the concept and definition of interface before , And the subclass definition of the interface Other uses , I also need to master some other syntax of interface .
DEMO: A subclass can implement multiple interfaces
If you want a subclass to implement multiple interfaces , Then use in implements Then use commas to separate the interfaces that need to be implemented .
DEMO: Interfaces can inherit from each other
Interface inheritance interface also uses “extends” keyword , Subclasses implement all interfaces ( Including the parent interface ) Abstract method of .
DEMO: Inheritance and realization
A subclass not only inherits an abstract class, but also implements interfaces .
If a subclass inherits the abstract class and implements the interface , Then the subclass must implement the abstract method in the abstract class , At the same time, we should also implement the abstract methods in the interface .
summary :
1、 A class can implement multiple interfaces , In fact, this solves the single inheritance limitation of inheritance . stay implenmts Then use commas to separate the interfaces to be implemented
2、 Interface can inherit interface , The keywords used are also “extends” Realization
3、 A class can inherit abstract classes and implement interfaces .
4、 Use between abstract classes and subclasses “ Inherit ” To describe the relationship between them , Interface and its implementation : Subclasses use “ Realization ” To describe the relationship between them .
There is a complete Java primary , Advanced corresponding learning routes and materials ! Focus on java Development . Share java Basics 、 Knowledge of principle 、JavaWeb actual combat 、spring Family bucket 、 Design patterns 、 Distributed and interview materials 、 Open source project , Help developers grow !
Welcome to WeChat official account. : Code state Lord