有什么办法在Java中扩展两个或多个类? [英] Any way to extend two or more classes in java?

查看:59
本文介绍了有什么办法在Java中扩展两个或多个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Java不允许我们扩展多个类.我知道接口也存在,并且我这次不想使用它们.是否存在某种技巧或变通办法来扩展Java中的多个类?如果是,请同时提供示例代码.

I know that Java does not allow us to extend more than one class. I know that interfaces also exist and I don't want to use them this time. Is there some kind of trick or workaround to extend multiple classes in Java ? If yes, please include the sample code also.

推荐答案

您可以通过界面和组成轻松地 .

You can do it easily with interfaces and composition.

问题是为什么你会问这样的事情?为什么不希望在此时"使用接口?

The question is why you would ask such a thing? Why do you not want to use interfaces "at this time"?

您必须知道Java仅允许实现的单一继承.您在SO上度过了七个月,因此,您肯定必须知道如何使用搜索功能.这个问题在这里反复问过.

You have to know that Java only allows single inheritance of implementation. You've spent seven months at SO, so surely you must know how to use the search feature. The question has been asked here repeatedly.

更有创造力.没有理由JPanel必须是可观察的.JPanel用于渲染.我同意其模型数据可能希望是可观察的.一定要用构图做到这一点.

Be more creative. There's no reason that a JPanel has to be Observable. JPanel is for rendering. I agree that its model data might want to be Observable. By all means do it with composition.

这篇关于有什么办法在Java中扩展两个或多个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆