Interfaces


Abstract classesand methods
Interfaces
However, an interface is more than just an abstract class taken to the extreme, since it allows you to perform a variation of "multiple inheritance" by creating a class that can be upcast to more than one base type.
To create an interface, use the interfacekeyword instead of the classkeyword. As with a class, you can add the publickeyword before the interfacekeyword ( but only if that interface is defined in a file of the same name). If you leave off the publickeyword, you get package access, so the interface is only usable within the same package. An interface can also contain fields, but these are implicitly static and final.
Complete decoupling
Creating a method that behaves differently depending on the argument object that you pass it is called the Strategy design pattern. The method contains the fixed part of the algorithm to be performed, and the Strategy contains the part that varies. The Strategy is the object that you pass in, and it contains code to be executed.
“Multiple inheritance” in Java
When you combine a concrete class with interfaces thisway, the concrete class must come first, then the interfaces.
Extending an interfacewith inheritance
Name collisions when combining Interfaces
Adapting to an interface
Because you can add an interface onto any existing class in this way, it means that a method that takes an interface provides a way for any class to be adapted to work with that method.This is the power of using interfaces instead of classes.
Fields in interfaces
Because any fields you put into an interface are automatically static and final , the interface is a convenient tool for creating groups of constant values.
Initializing fields in interfaces
Since the fields are static , they are initialized when the class is first loaded, which happenswhen any of the fields are accessed for the first time.
Nesting interfaces
Interfaces may be nested within classes and within other interfaces.
As an added twist, interfaces can also be private, notice that when you implement an interface, you are not required to implementany interfaces nested within. Also, private interfaces cannot be implemented outside oftheir defining classes.
Interfaces and factories
















在网络设备中,`show interfaces Gi` 命令用于查询以 `Gi`(Gigabit Ethernet,千兆以太网)开头的接口的相关信息。该命令会显示接口的各种统计信息,涵盖接口状态、带宽使用、错误计数等方面。 以思科设备为例,执行 `show interfaces Gi` 命令后,可能会得到如下输出: ```plaintext Switch# show interfaces Gi GigabitEthernet0/1 is up, line protocol is up Hardware is Gigabit Ethernet, address is 001a.2f55.c601 (bia 001a.2f55.c601) MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 100 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set Keepalive set (10 sec) Full-duplex, 1000Mb/s, media type is 10/100/1000BaseTX input flow-control is off, output flow-control is unsupported ARP type: ARPA, ARP Timeout 04:00:00 Last input 00:00:00, output 00:00:00, output hang never Last clearing of "show interface" counters never Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 Queueing strategy: fifo Output queue: 0/40 (size/max) 5 minute input rate 0 bits/sec, 0 packets/sec 5 minute output rate 0 bits/sec, 0 packets/sec 100 packets input, 12000 bytes, 0 no buffer Received 100 broadcasts (0 multicast) 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 watchdog, 0 multicast, 0 pause input 0 input packets with dribble condition detected 50 packets output, 6000 bytes, 0 underruns 0 output errors, 0 collisions, 1 interface resets 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier, 0 pause output 0 output buffer failures, 0 output buffers swapped out ``` 从上述输出中可以获取到接口的状态(如 `up` 表示正常工作)、硬件类型、带宽、双工模式、输入输出流量、错误计数等信息。这些信息对于网络故障排查、性能监测等工作非常有帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值