Welcome back friends, we have been learning inheritance. And now here in this lecture, we're going to learn about final method, final keyword, when we have a base class and the derived class and we have different methods, variables or constructors in the parent class, that we do not want to alter or modify so many ways class or different methods, even in this same class, we want to define it once and for all. We do not we do not want to change this definition or value. So how we can implement such things we can implement add a keyword called final, before vertical integration of such variables and matters. So let's start. The final final keyword can we use to restrict a user?
It can be used in various contexts, with variable method and class. Our final keyword can be applied to different set of values and the final keyword, final variable that has no value can recall as blank final value, which can be only initialized with a constructor. So, here is a scenario where we can use in different cases, first case is a final variable cannot be modified, we have a class called a we have a final value variable called a smally. of type integer. And we have also declared a we as a final variable. So, we cannot change the value or modify the value anytime in the future once it's declared.
Then, we have a base class called a and derived class called v. If a Class A is declared as final, it cannot be extended or inherited. Similarly, we have a final method, which cannot be overridden however it can be called or executed from the base class from the child class as well as base class. We cannot change the value, we cannot really clear the pattern. So, here is a final variable. This is a program where we have declared a variable called speed limit equals to 90 as a final variable. So, when it is declared as final, we can not change the value in either of the cases we cannot change anywhere and the value will remain the same.
Similarly, we have final matter this declaration could not change we have a method called raw which is declared as final in the base class by when type class inherit from the base, the definition could not be changed and we call that function it will execute the base method only. Similarly, we may have final class that could not be inherited at all. Weekly edition if we will right accent it won't work anyway. So this was about keyword final that we can use during inheritance. To have better control over a keyword such as Super this finals allows us better control over different set of languages. So by building an AR solution, write your own programs and implement various solutions.
I will then keep learning and keep moving ahead