Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtypes in java

Tags:

java

subtype

If I have 4 distinct Java types (call them A B C D), and A is a subtype of B and A is a subtype of C and B is a subtype of D and C is a subtype of D, is this legal? Are there any examples out there?

Drawing the diagram:

           D
          | |  
        |     |
       B       C
        |     |
          | |
           A

So D is the supertype. Thanks!

like image 384
pauliwago Avatar asked Feb 17 '23 13:02

pauliwago


1 Answers

This is not legal with inheritance, as Java as a language does not support multiple inheritance.

However you can do this by implementing multiple interfaces, which is a different thing from multiple inheritance.

So yes it's possible and for you to do this so far as you can check if something is an instance of an interface but this is not the same as a class type, and your diagram would look a tad different to the one you have drawn.

like image 53
krystan honour Avatar answered Feb 27 '23 11:02

krystan honour