What is the purpose of making a class final as we can't further inherit it then why do we make a class final? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the purpose of making a class final as we can't further inherit it then why do we make a class final?

What is the need of making a class final?

28th Nov 2018, 4:04 AM
Dharm Vashisth
1 Answer
+ 1
For example you're making a library for lets say graphic. And put the graphic as a class, you have a lot of equation inside so it able to display properly. But what if there's someone who using your lib inherit the class and override one of those method ? There's a chance that it'll broke the algorithm when he use his class. By using final everyone cant copy and alter those methods
28th Nov 2018, 4:20 AM
Taste
Taste - avatar