ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

Final Keyword in Java

Final keyword in Java can be used with class, object, method and variables. It is used in order to restrict the user.

If final keyword is used along with the class, then that class cannot be extended.

If final keyword is prefixed before method then we will not be able to override that method.

If final keyword is used before variable/ object then we will not be able to reinitialize that object or variable.

  1. Syntax for using final keyword.
  2.  
  3. public final class A{
  4.  
  5.  
  6.  
  7. }
  8.  
  9. public final void method1 {
  10.  
  11. }
  12.  
  13. final int temp;

 

If a user is trying to violate any rule, user will get compile time error.

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!