Sunday, February 8, 2015

Final keyword sample code in Java

Variable with final keyword will make the variable constant.
Eg: int speedlimit=90;//final variable

Java final method
If you make any method as final, you cannot override it.

Java final class
If you make any class as final, you cannot extend it.




package com;

public final class TestFinal {

static final String str = "TESTING";

public static void main(String args)
{
System.out.println();
}

public final void test()
{
System.out.println("Testing this method with final");
}

}

No comments:

Post a Comment