Java program to implement use of Final Keyword on Class, Method and Variable
Simple Java program to use Final Keyword on following items:
- Variable
- Class
- Method
Code:
class a{
final int a=5;
void setfinala(int x)
{
a=x;
}
final void finalmethod()
{ System.out.println("Final method.");
}
}
class a1 extends a{
void finalmethod()
{
System.out.println("Final method in extended class.");
}
}
final class b{
}
class c extends b{
}
class p33{
public static void main(String args[]){
a obj = new a();
a.setfinala(3);
}
}
Comments
Post a Comment