Final Key word in Java
If you are using final keyword any one of the following you
can’t modify or you can’t override and you can’t extend.
Final can be used for the following things
1)
Variable
2)
Method
3)
Class
Will discuss one by one
1)
Variable : if you declare variable as private
and initialize the value then you can’t change that value.
2)
Method : if you are declaring method as final
you can’t over ride that method
3)
Class: if you are declaring class as final you
can’t extend that class
Will discuss basic question on
final keyword.
1)
Is final method inherited?
Answer : yes, we can inherited but remember we can’t over
ride the method
2)
Can we initialize blank final variable
Answer : yes, but only in constructor we can initialize




0 comments:
Post a Comment