从接口调用某些方法,而不覆盖JAVA中的所有方法 [英] Call some methods from interface without override all the methods in JAVA
本文介绍了从接口调用某些方法,而不覆盖JAVA中的所有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,我在Java中遇到一个问题:我想实现一个结构,但是我在执行该结构时遇到了一些困难,有人可以帮助我吗。
Friends, I have an issue in Java: I'd like to implement one structure but I'm facing some difficulty in doing it, can anyone help me.
interface samp1{
method1()
method2()
method3()
}
interface samp2{
method4()
method5()
}
class Samp implements samp1,samp2
{
// this class needs only method1 from interface samp1 and method 4 from interface samp2
// I don't want to override all the methods from interface
}
有人可以为此提出一些解决方案吗?
can anyone propose some solutions for this?
是否有任何可用的设计模式?如果是这样,请提供引用链接。
Is there any design pattern available for this? If so, please provide links to reference.
预先感谢。
推荐答案
接口是合同。它说我的类实现了这些方法的 all 。
An interface is a contract. It says "My class implements all of these methods".
请参阅: http://docs.oracle.com/javase/tutorial/java/concepts/interface.html
如果您不想这样做,请不要使用接口。
If you don't want that, don't use an Interface.
这篇关于从接口调用某些方法,而不覆盖JAVA中的所有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文