A final keyword has a numerous way to use.
A final class cannot be subclassed.
A final method cannot be overridden by sub classes.
A final variable can apply only be initialized once.
Example:-
public Class Hello
{
public final int number;
{
Hello() //Use a constructor
{
number=10;
}
}
Public Class MyClass
{
public static void main(string[] args)
{
Hello hel=new Hello(); //Use a Hello Class
hel.number=20;
}
}
public Class Hello
{
public final int number;
{
Hello() //Use a constructor
{
number=10;
}
}
Public Class MyClass
{
public static void main(string[] args)
{
Hello hel=new Hello(); //Use a Hello Class
hel.number=20;
}
}
0 Comments:
Post a Comment