How to extend 2 classes?

modellero picture modellero · Feb 17, 2012 · Viewed 18.3k times · Source

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 that?

Answer

poitroae picture poitroae · Feb 17, 2012

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.

class MyService extends Service{
  ...
}

class MyList extends ListActivity{
    MyService service = new MyService();
}