user2949783
user2949783

Reputation: 11

inherit from 2 already defined classes in java

Im trying to inherit from multiple classes, I have been told I should use interface, but the problem is that these are predefined classes in java, such as example activity class and Fragment class

Help would be appreciated!!

Upvotes: 1

Views: 122

Answers (3)

VJ Vélan Solutions
VJ Vélan Solutions

Reputation: 6554

You could inherit from multiple classes in C++ and not Java. You need to rethink your strategy.

Upvotes: 1

span
span

Reputation: 5624

You can only extend from one class in Java. In your case, FragmentActivity seems to be the right choice. Otherwise interfaces are the way to go. Fragments and Activities are different creatures in the android lifecycle and can't be treated equal.

Note that you can have instances of however many different classes in your own custom class though. But that class doesn't have to extend anything.

Upvotes: 1

An SO User
An SO User

Reputation: 24998

It seems like a contradiction in design, doesn't it ? An Activity may contain Fragments. If you make something both an Activity and Fragment, what are you trying to do ? =)

No, you can never inherit from two classes in Java.

Upvotes: 1

Related Questions