Reputation: 534
I am using SherlockActionBar library in my project.And my class is extending an abstract class SherlockActivity
public class AllAppsInfo extends SherlockActivity{}
In mean while i want to extend my AllAppsInfo with FragmentActivity as well.Which is not allowed due to negligence of multiple inheritance in java.
I have done some search, composition is the solution but how to use it in this Scenario? Neither i can make abstract Sherlock class a interface nor same be done with Fragment Activity class .
Upvotes: 0
Views: 573
Reputation: 534
I have solved this issue by extending my class with SherlockFragmentActivity
public class AllAppsInfo extends SherlockFragmentActivity{}
Upvotes: 1
Reputation: 13882
Try Composition.
You can refer here too.
The funda is simple:
class A
{
void aMethod() {}
}
class B
{
void bMethod() {}
}
class C
{
void cMethod() {}
}
if you want to call aMethod()
and bMethod()
from cMethod()
; you can do following way:
class C extends A // Inheritance
{
B aBObject = null; // Composition
void cMethod()
{
aMethod();
aBObject = new B();
aBObject.bMethod();
}
}
Upvotes: 3
Reputation: 3443
Java has not full multiple inheritance, C++ has. You need workarounds to do it like composition
Upvotes: 0
Reputation: 4418
Yes, In Java we do not have multiple inheritance.
You have two options ahead of you.
Upvotes: 1