如何在一个类中继承两个类的属性?
我有一个程序需要继承broadcastreceiver和MapActivity的属性。实际上,我想在收到朋友发来的短信时发送当前位置(经度和纬度)。我有一个代码,但不知道如何继承这两个类的属性。这是我的代码:
请给我一些想法来解决这个问题或任何其他方法(如果这是不可能的)?
I have a program which requires to inherit the properties of both broadcastreceiver and MapActivity.Actually I want to send current location (longitude and latitude) on receiving an sms from friend.I have a code with me but don't know how to inherit the properties of both the classes.Here is my code:
Please give me some idea to solve this or any other approach if this is not possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于java禁止多重继承,你实际上不能。当您计划申请隐蔽服务时,您不需要任何活动 - 只需一个广播接收器
它与位置服务通信并将获得的位置发送到某处。
As java prohibits multiple inheritance, you actually can not. As you are planning application for covert srveyliance, you do not need any activity - just a broadcast receiver
which comunicates with location service and sends obtained location somewhere.
Java 不支持多重继承,但您可以实现任意数量的接口,因此可以通过组合来实现。这是一个粗略的轮廓,但有很多方法可以做到这一点。基本思想是,对于您想要继承的一个或两个类,您可以引用某个实现,并通过委托给实际实现来公开相同的接口。
Java doesn't support multiple inheritance, but you can implement as many interfaces as you'd like so you can do this through composition. Here is one rough outline, but there are many ways you could do it. The basic idea is that for either or both of the classes that you want to inherit from you have a reference to some implementation and you expose the same interface through delegation to the actual implementation.