When we declare all variables and methods in a class as final, we are restricted the concept of override.
Then, "what is the reason we want to restrict IS-A relationship in an OOP language( even we restrict IS-A relationship, this language has Has-A relationship) by using final class?"
My point is we can not restrict the accessing the members of our class any way, then give an easy access by allowing IS-A relationship. Otherwise it is a headache to create objects and all? (in my view 'access' not includes modifications)
If I miss any important theme of programming , please excuse me. And tell me, what is it?
Is there any necessity to declare a class as final class?
Necessity, no. Declare a class final if you want to forbid extending it. This can prevent programming errors. For example it's a recommended practice to make utility classes with only static methods to be final, as inheriting from such class wouldn't make sense, and be clearly a programming error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With