接口及实现类官方理解

https://docs.oracle.com/javase/tutorial/java/concepts/interface.html

1.

Bicycle bicyle = new ACMEBicycle (); 这句话的含义:检查实例化对象ACMEBicycle是否implements Bicyle接口,并给予这个对象bicyle名字。

If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.

2.

*To actually compile the ACMEBicycle class,*

文档中的这句话含义就是被编译的其实是实现类。因此在操作bicyle对象的时候考虑的应该是ACMEBicycle类中重写Bicyle接口的method。
如果按照上面所说考虑问题,那么操作bicyle对象的时候就会遇到一个问题,若实现类ACMEBicycle不是自己编写的那么怎么知道其中有哪些方法能被操纵,这时候就可以寻找接口或类的官方说明文档了解这个类方法,但是要记住编译一定是编译实现类的方法。

猜你喜欢

转载自blog.csdn.net/weixin_45177101/article/details/122216941
今日推荐