![]() ![]() What is the final modifier in Java? ExampleThe final keyword is also known as a final modifier in Java. Horstmann's Core Java Volume 1 and 2, which is both readable, easy to understand, and comprehensive enough to learn Java in deep. One of the good Java books for the beginner is Cay. That will make you progress more in less time. ![]() If you are a beginner, just started learning Java, I suggest you refer at least one book alongside your research and practice. This is why String is also made final in Java. Why you make a class final? doesn't it take your right of code reuse via Inheritance and extending its functionality? This is usually done to protect the class's invariant due to security reasons. In Java, you can not extend a final class to create sub-classes. You can also use the final keyword with classes to make sure they are not extensible. in template design pattern, the method which keeps the algorithm, also known as the template method should be final because the outline of the algorithm should be changed by the child classes. It is also done to prevent someone deliberately or accidentally changing the core logic of the method by overriding it e.g. This is usually done to signal that method is complete and it's not designed for extension. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |