Saturday, January 16, 2016

What is final method?

Final Methods:
  1.  Making a method final ensures that the functionality defined in this method will never be altered in any way.
  2. Similarly, the value of a final variable can never be changed.
  3. Final variables behave like class variables and they don not take any space on individual objects of the class.
What is Final variable and when to use?

Final Variables:
1.       final variables can be assigned only once(compiler ensures it)
2.       Declaration and initialization together
3.       first declare then initialize once before constructor finished(i.e: instance block constructor)
4.       static block finished for static final

When to use?
If we need to initialize logically/conditionally.

No comments:

Post a Comment