Can we Inherit Final Class in Java Language

Well we know that Inheritance is the very important part of any programming language, the same is with the Java programming language. We are talking about the final keyword usage. So the question is, can we inherit final class in Java language. If you had read my earlier post about final keyword then you should know that If we declare any class as final, it can’t be inherited. So the answer to the question is NO.  Since now you know the answer, you should try to practically prove it.

Check out this program code including final keyword: -

final class fin2
{

}
class derived extends fin2
{

}

Here we have two classes fin2 and derived. fin2 is a final class and derived is a simple class. They are trying to build inheritance relationship because

class derived extends fin2

Since fin2 is a final class, it cannot be inherited. If you compile this program, there will be an error message. Check out the compilation of this java program below

So now we know that final class can not be inherited in java language.


Share this Post[?]
        

No Comments

Leave a reply