Home Javatutorials Final Methods - Java Tutorials



Final Methods - Java Tutorials
Posted on: April 18, 2011 at 12:00 AM
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.

 

Related Tags for Final Methods - Java Tutorials:


More Tutorials from this section

Ask Questions?    Discuss: Final Methods - Java Tutorials  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.