Skip to content Skip to sidebar Skip to footer

How To Extend 2 Classes?

This might be a silly question, but I'm struggling on how to make my class extend 2 classes at the same time. I'm trying to make a SERVICE that uses ListActivity. How could I do th

Solution 1:

Java or android Doesn't Support Multiple Inheritance

Solution 2:

I assume you are coding in the Java programming language. Then the simple answer is: You don't. Java does not support deriving from multiple classes. Make your ListActivity contain a Service.

classMyServiceextendsService{
  ...
}

classMyListextendsListActivity{
    MyServiceservice=newMyService();
}

Solution 3:

In Java you can't extend more than 1 class at the same time. However, you can implement more than 1 interface (but this is not about your task).

You should look for bound service

Solution 4:

No, it is not possible. You may need to re-architect your implementation.

Solution 5:

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

Post a Comment for "How To Extend 2 Classes?"