How to extend 2 classes?

It may be a stupid question, but I try my best to have my class extend 2 classes at the same time. I am trying to make a service that uses ListActivity. How can i do this?

+4
source share
6 answers

I assume that you are coding in Java programming language . Then the simple answer is: you will not do it. Java does not support output from multiple classes. Add ListActivity Service .

 class MyService extends Service{ ... } class MyList extends ListActivity{ MyService service = new MyService(); } 
+1
source

Java or Android does not support Multiple Inheritance

+1
source

In Java, you cannot extend more than 1 class at a time. However, you can implement more than 1 interface (but this does not apply to your task).

You must look for a related service.

0
source

No, It is Immpossible. You may need to reverse engineer your implementation.

0
source

You can never directly extend 2 classes, you need to use some tricks and create several interfaces to make it work. Here is the guide: http://csis.pace.edu/~bergin/patterns/multipleinheritance.html

0
source

Assuming that you are referring to this type of service , you cannot do this at all; regardless of the fact that Java does not have multiple inheritance. Services also can not be. You must create a Service and a separate ListActivity, and use a binder to communicate between them .

If you want to inherit the functionality of two classes, use the delegation template .

0
source

Source: https://habr.com/ru/post/1397052/


All Articles