Home Javatutorials Final Methods - Java Tutorials
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Final Methods - Java Tutorials

Advertisement
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.

 

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Ask Questions?    Discuss: Final Methods - Java Tutorials  

Post your Comment


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

what is this
anusha
November 30, 2011
core java

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

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

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

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

tell more about final argument
chandra babu
August 10, 2012
java

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
pankaj
September 27, 2012
java

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
DMCA.com