Welcome to Srini's blog

Sunday, April 4, 2010

Use of final keyword in JAVA

The keyword final has 3 uses.
1. It can be used to create the equivalent of a named constant.
2. It can be used to prevent method overriding. method overriding is one of Java’s most powerful features, there will be neccessity to prevent it from occurring. To disallow a method from being overridden, specify final as a modifier at the start of its declaration. Methods declared as final cannot be overridden.
3. It can be used to prevent inheritance. Sometimes you will want to prevent a class from being inherited. To do this, precede the class declaration with final. Declaring a class as final implicitly declares all of its methods as final, too.

No comments:

Post a Comment