Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Monday, February 16, 2009

Program of Final class, Method and Variable

/**

* Write a example of Final class, Method and Variable. Also explain the same.

*

*

*/

public final class FinalTest { // final class

// final variable

private final static float PI = 3.14f;

// final method

public final void displayPI() {

System.out.println("Final Variable : PI=3.14f : \nOnce its value is assigned, can't alter it!!");

System.out.println("\nFinal Method : displayPI() \nA method that can't be overridden by child class!!");

System.out.println("\tValue Of PI : " + PI);

System.out.println("\nFinal Class: FinalTest : \nA class that can't not be inherited!!");

}

/**

*

* execution begin from here

*

* @param args

* command line arguments

*/

public static void main(String[] args) {

new FinalTest().displayPI();

}

}

No comments:

Post a Comment

Followers