Final Methods - Java Tutorials

final methods



The final Keyword in Java

In Java, final keyword is applied in various context. The final keyword is a modifier means the final class can't be extended, a variable can't be modified, and also a method can't be override.

final classes

The class declared as final can't be subclass or extend. The final class declared as follows :

public final class MyFinalClass

final methods

The final method  can be declare as follows:

public final String convertCurrency()

The final method can't be override in a subclass.

final fields

The field declared as final behaves like constant. Means once it is declared, it can't be changed. Before compiling,only once it can be set; after that you can't change it's value. Attempt to change in it's value lead to exception or compile time error.

You can declare the final fields as :

public final double radius = 126.45;

public final int PI = 3.145; 

The fields which are declared as static, final and public are known as named constants. Given below a example of named constant :

public class Maths{
public static final double x = 2.998E8;

final method arguments

You can also declare method's argument as final. The final argument can't be modified by the method directly.


Share on Google+Share on Google+

Final Methods - Java Tutorials

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Final Methods - Java Tutorials  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
September 6, 2011
final method

what is this
November 30, 2011
core java

I need a program with final method and clear explanation.....
January 3, 2012

What is Multithreading? Explain different ways of implementation of multithreading in java
January 17, 2012

Plz give an example of final argument.
May 11, 2012

we want java program using final declaration
July 16, 2012
final argument

tell more about final argument
chandra babu
August 10, 2012

what are the final methods we are using in java
adarsh kumar singh
September 15, 2012
java final method program

i want to sourcecode for pratics
September 27, 2012

final means last value assigned to var,and final method as a ROW agent that can't be works for other class or country
shrikant bhardwaj
December 10, 2012
final methods in java

how many methods are final in java. plz tell me 5 of them