Multiple & Hybrid Inheritance allowed in Apex?

I should know this, but does Apex support multiple inheritance? I used to do it in C++. I ‘m trying to model a class that looks like:

Mother –>kid <— Father

Also what about hybrid? where the mother and father are derived from a single parent?

Answer

Syntax for Apex is mostly based on Java and it does not allow multiple inheritance.

Hybrid (Not allowed)

Virtual Class A
Virtual Class B extends A
Virtual Class C extends A
Class D extends B, C

Multiple (Not allowed)

Virtual Class A
Virtual CLass B
Class C extends A, B

Multi level (Yes)

Virtual class A
Virtual class B extends A
Class C extends B

Salesforce does allow multiple interface implementation.
To inherit any class, it must be defined with keyword Virtual.

You can read more about inheritance here.

Attribution
Source : Link , Question Author : PartOfTheOhana , Answer Author : Jitendra Zaa

Leave a Comment