-2

I have an application with the name MyApplication that extends from library application RoboInjectableApplication

public class MyApplication extends RoboInjectableApplication {

}

But now I want MyApplication to extends from another library application XWalkApplication so that my application have extension from RoboInjectableApplication and XWalkApplication how to achieve that

hariszaman
  • 8,202
  • 2
  • 40
  • 59
  • 1
    Java doesn't support extending multiple classes. You should think of a way to transform this into composition. – Danail Alexiev Jul 26 '15 at 14:14
  • possible duplicate of [Multiple Inheritance in java](http://stackoverflow.com/questions/1262447/multiple-inheritance-in-java) – hariszaman Jul 26 '15 at 14:38

3 Answers3

0

This is not possible Java only allows one super class. You may check the source codes of both classes and write a merged class which has all compatibilities.

If you would need a different super class in a different context you may try the flavors of Android Studio. There you can override classes which generates a different APK.

rekire
  • 47,260
  • 30
  • 167
  • 264
0

In java you can extend only one class.

You can check if you can use class field (variable) to have XWalkApplication functionality - this is often called composition.

Another way is as already suggested, you can merge the source code.

Another way is to play with interfaces if this is possible.

Nick
  • 9,962
  • 4
  • 42
  • 80
0

Multiple inheritence is not supported in java. It will cause ambiguity in few scenarios. One of the most common scenario is Diamond problem. You can read more about this from here.

In short it is not possible to extend from multiple classes.

SubinM
  • 394
  • 3
  • 7