I want to know when I should mark my class as final ?
And if not can I extend a final class?
I'm using a ipinfodb api and its a final class that I want to use in my regular class.
Use composition instead of inheritance. The entire singular purpose of final
classes is that you're not meant to inherit from them. You need to make a class which simply uses an instance of the final
class internally.
you can't extend final class. Extend means inheritance. What means "include a final class in my class"?
You can make your own class, and then into that class create a member of your final class var m_yourFinalClassObj = new MyFinalClass;
Or just declare it:
class MyClass
{
var m_yourFinalClassObj;
...
... and in the constructor go and initialize it (create the object of the final class)
Final class is nothing more than a final class. It means, you just can't create a child class of a final class(No inheritance supported). You also can't override its' methods. But you actually can include it and use it in other classes.
the final class is same as sealed class in c# which means it is sealed it is further more cant inherited with other class however use this class by making its object in another class.