java interfaceof,Other usage syntax of java interface

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

741d1ff616f9221aa6efa85428904c46.png

d8c6c1b22ca025302b5ebf14a9f7b881.png

8cb54d4bf806963c55a509bdd1f23b1d.png

c62195ddbc7953baf15791b74190dc2f.png

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

2884e45c7917486d5e391ac869b425fa.png

9f68fc3a966bc0907b6ecec8a363de92.png

626f29a431ef1a7ffe0981187d3a37a7.png

5de4e0a54fb9450a5b36dd102241bdfa.png

8cddea12c5fe2d155beaf39b52f1a9b1.png

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 .

4f45b3480190e0d8063428811757b95a.png

9783734ee91d5e8ebcf3f2cc44a730de.png

86016ca6bd9848ce1346d6a9795e8063.png

7698c5ca7bba7e6f5f1477eaf67ae0c4.png

84ad9a2f47fbae970129d93f0bfe5a56.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值