Friday 22 April 2016

How to use final keyword in java



Final keyword:-If we use final before class then we cannot extend the class.
We cannot reuse the method by using final keyword.

class Test{
final void show()
{
System.out.println("Hello Friends");
}
}
class Main extends Test{
void show();
public static void main(String args[]){
final int x=10;
System.out.println("Before swapping :- "+x);
int y=20;
x=y;
System.out.println("After swapping :- "+x);
}
}

OUTPUT:-
Compile Time Error